Skip to content

Instantly share code, notes, and snippets.

@groyoh
Last active August 29, 2015 14:28
Show Gist options
  • Save groyoh/09af5e25fdfbc42eb0bc to your computer and use it in GitHub Desktop.
Save groyoh/09af5e25fdfbc42eb0bc to your computer and use it in GitHub Desktop.
Delegation to array
class Delegator
def initialize(array)
@array = array
end
def method_missing(method, *args, &block)
@array.send(method, *args, &block)
end
end
puts Delegator.new([1,2]) + Delegator.new([2,3])
__END__
On MRI 1.9.3 & 2.1.2:
1
2
2
3
On JRuby 1.7.15:
TypeError: can't convert Delegator into Array
+ at org/jruby/RubyArray.java:3062
method_missing at delegate_array.rb:7
(root) at delegate_array.rb:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment