-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Ruby 1.8.7 compatibility #43
Conversation
Cool! I'm actually kinda surprised it was that easy... does |
I can’t find any instances of |
It’s actually not as easy as I initially thought. Working on making the specs pass on various Ruby implementations now. |
Hmmm, it looks like this will require removing |
Thoughts on adding a dependency on the backports gem instead? Or what about On Tue, Dec 31, 2013 at 4:23 PM, Erik Michaels-Ober <
Avdi Grimm I only check email twice a day. to reach me sooner, go to |
Backports is cool project but it can make debugging more complicated. I prefer the idea of |
Okay, I’ve got the specs passing on MRI 1.9.2 through |
Working on it! |
While I'm waiting for 1.8.7 to install... a little buzzing at the back of my head is saying something about parsing of blocks. First thing I want to try will involve switching between curly braces and do/end. |
This is super weird. I can't reproduce it with methods I define in IRB, but it's definitely happening under test. |
OK, so this is pretty nuts. If I load up naught in IRB 1.8.7 and generate a null class, then include the conversions module, I can reproduce this behavior. But if I copy-and-paste the source of |
All I can think is that this is a bizarre bug in 1.8.7 that only occurs when a method is included from a module. I don't know how to work around it other than to put a conditional around the tests for the conversion functions. But that doesn't help anyone to actually use the functions in 1.8.7. This is painful, but you might move the definitions of the conversion functions into a proc, and provide a way to instance_eval that proc in the current context rather than including the generated Conversions module. That might work in 1.8. |
I agree with your conclusion that this is being caused by some bizarre bug in Ruby 1.8.7. Frankly, I’m surprised that I’ve never encountered it before and I have no recollection of reading about it around the time 1.9 was released. For kicks, I tried requiring
I had to read that sentence five times before I actually understood what you’re proposing and now my head hurts. I will give that a try, just as soon as my head stops hurting. Thanks for taking the time to look into this. I was completely stumped. |
I had one other thought about this, which is to have optional lower-case versions of the conversion functions. I haven't tested to see if this gets around the bug tho. |
I just tested with lower-case method names and I get the same errors. |
This is such a weird-ass bug.
|
Argh, I really should have remembered that, it was a big deal to me when On Tue, Jan 7, 2014 at 11:40 PM, Erik Michaels-Ober <
Avdi Grimm I only check email twice a day. to reach me sooner, go to |
This isn’t pretty but it solves the issue with blocks on Ruby 1.8. Unfortunately, it breaks tracing. Two steps forward, one step back. 🐸 |
Can you fix tracing by supplying the file and line args to eval? On Wed, Jan 8, 2014 at 2:52 PM, Erik Michaels-Ober <notifications@github.com
Avdi Grimm I only check email twice a day. to reach me sooner, go to |
The first thing I tried (which requires the meth = mod.method(method_name)
define_method("__real__#{method_name}", &meth)
file, line = meth.source_location
class_eval <<-EOM, file, line
def #{method_name}(*args, &block)
__real__#{method_name}(block, *args)
end
EOM Unfortunately, this did not fix it. What am I doing wrong? |
I was just thinking FILE and LINE, but I'm probably missing
|
That will set the source file and line to |
There may be a more elegant way to do this but I was pretty happy just to get it working across all major Ruby versions/implementations. Very curious to get your feedback. |
@@ -8,6 +8,4 @@ def self.build(&customization_block) | |||
builder.customize(&customization_block) | |||
builder.generate_class | |||
end | |||
module NullObjectTag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: What happens when someone uses config.base = Object
? Can we still identify a null object as a null object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, no. I’ll revert https://github.com/sferik/naught/commit/9d7872e86673073e2a9576c14fe7449713f54548.
Rename for consistency and clarity vs. implicit_conversions_spec.rb.
I tried doing the same thing with alias_method/undef_method but it caused errors on JRuby.
This is required to support Ruby 1.8 and earlier, which doesn't allow define_method to take a block that takes a block argument. See http://coderrr.wordpress.com/2008/10/29/using-define_method-with-blocks-in-ruby-18/
ConversionsModule was previously a class that needed to be initialized with two arguments: null_class and null_equivs. Instead, these arguments are passed via Module#included by setting a constant on the null class, including the module in the null class, and then removing the constant and undefining the included methods.
I’ve restored |
Nope, I think I'm good with it!
|
🐣 🐥 🐤 🐔 🥚 I’ve already committed to a branch in the According to (RubyGems.org)[http://rubygems.org/gems/naught], the current version of Naught has about 1,200 downloads since November 8 or about 600 per month. The latest version of the |
It’s been a few day since you said this looked good but I can’t help but noticing that it’s still not merged. If you’re willing to make me a collaborator on the project, I’d be happy to merge it myself and help maintain the project going forward. |
I'm merging this. Thanks for all your hard work! And yeah, I'd be happy to make you a collaborator. I kind of want to think about where we go from here... one of the reasons I built this library was as a way to demonstrate a number of metaprogrammer techniques, and the 1.8.7 compat necessarily means switching to... sub-optimal techniques. I'd like to get your thoughts on how to maybe restore some of the more "ideal" metaprogramming demonstrations. I guess the simplest thing would be to just wait until you officially sunset 1.8 support in the Twitter gem, and then do a rewrite. Another thought I had was to isolate some of the worst kludges into their own files and maintain two versions of those files one for 1.8 and one for >1.8. Then conditionally load the correct files based on Thoughts? |
I'm also thinking of stamping this as the 1.0 release. Being used in a major gem like twitter seems like a good time to lock down the API. |
The only issue with releasing this as version 1.0.0 is that locks you into supporting Ruby 1.8.7 until you release version 2.0.0. If you’re planning to remove Ruby 1.8.7 support in the relatively near future, (say, On the other hand, the whole point of this patch is so that I can depend on this gem in production, and according to Semantic Versioning:
Maybe releasing version 2.0.0 in 6 months isn’t so bad after all? Firefox and Chrome have taught us that there’s no shame in being at version 26.0 or 32.0.1700.77.✡ It’s not like there’s any shortage of positive integers. In fact, quite the opposite. ✡ Chrome’s version number has been increasing by (on average) 0.01630988786 per day. If they continue at the current pace for the next 50 years, when I am 80 years old, Chrome’s version number will be 297.852803088. Update: Replaced asterisk with Star of David, since GitHub-Flavored Markdown converts asterisks to bullet points. See also. |
@avdi Any additional thoughts on shipping a new version and what number it might have? |
As also tweeted: let's go with 1.0.0. I've added you as a gem owner since I keep getting sick and having snowstorms and assorted other excuses for not getting around to it :-) |
Okay. I’ve reviewed all open issues and pull requests, updated the |
Erik, Thanks again for all your work and patience on this. I never imagined this library would be 1.8-compatible! |
I’d like to use Naught to replace
Twitter::NullObject
in thetwitter
gem, however, the current version of the gem still supports Ruby 1.8.7 and I don’t want to bump the major version just to add Naught.I also took this opportunity to add other Ruby versions and implementations to the Travis CI configuration (JRuby, Rubinius, etc.).
Do you have any objection to supporting Ruby 1.8.7, at least through June 2014?