Skip to content

Instantly share code, notes, and snippets.

@banister
Created February 17, 2011 05:09
Show Gist options
  • Save banister/831013 to your computer and use it in GitHub Desktop.
Save banister/831013 to your computer and use it in GitHub Desktop.
# Ruby edge cases
# lambdas can no longer be used with instance_eval in Ruby 1.9.2
l = lambda { puts "hello world"! }
Object.instance_eval(&l) #=> invalid argument. This is due to the fact instance_eval now yields a value (the receiver) in 1.9
# module double inclusion
# module appear multiple times in inheritance chain
# behaviour of constants in class_eval
# Proc.new can create a proc from an implicit block
# behaviour of *[] in 1.8 vs 1.9
# class variables in singleton classes -- end up at toplevel
# behaviour of nested def (puts method on class even though receiver is object) vs def self.meth
* C ||= 5 (if C is undefined) raises a NameError in 1.8 but works fine in 1.9
* String.send(:attr_accessor, :x) creates PRIVATE accessor methods, rather than public. Does not behave this way in rubinius -- but does in jruby and MRI/YARV.
* symbol.to_proc.call(obj) will invoke private methods in 1.8, but only public methods in 1.9. This is likely intentional as 1.9 uses rb_funcall3() (public methods only) see sym_call() in string.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment