Skip to content

@ukd1 /weird.rb secret

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'delegate'
class X < DelegateClass(Integer)
def initialize(value, name)
value = Integer(value)
@name = name
super(value)
end
end
X.new(1, 'test')
@ukd1
Owner

2.0.0p247

2.0.0p247 :001 > require 'delegate'
 => true 
2.0.0p247 :002 > 
2.0.0p247 :003 >   class X < DelegateClass(Integer)
2.0.0p247 :004?>     def initialize(value, name)
2.0.0p247 :005?>         value = Integer(value)
2.0.0p247 :006?>         @name = name
2.0.0p247 :007?>         super(value)
2.0.0p247 :008?>       end
2.0.0p247 :009?>   end
 => nil 
2.0.0p247 :010 > 
2.0.0p247 :011 >   X.new(1, 'test')
 => 1 
2.0.0p247 :012 > 

2.1.0-p1

/Users/russ/.rvm/rubies/ruby-2.1.0-preview1/bin/irb
retinalols-3:Sites russ$ irb
2.1.0dev :001 > require 'delegate'
 => true 
2.1.0dev :002 > 
2.1.0dev :003 >   class X < DelegateClass(Integer)
2.1.0dev :004?>     def initialize(value, name)
2.1.0dev :005?>         value = Integer(value)
2.1.0dev :006?>         @name = name
2.1.0dev :007?>         super(value)
2.1.0dev :008?>       end
2.1.0dev :009?>   end
 => :initialize 
2.1.0dev :010 > 
2.1.0dev :011 >   X.new(1, 'test')
 => 1 
2.1.0dev :012 > 

2.1.0-p2

retinalols-3:Sites russ$ rvm use ruby-2.1.0-preview2
Using /Users/russ/.rvm/gems/ruby-2.1.0-preview2
retinalols-3:Sites russ$ which irb
/Users/russ/.rvm/rubies/ruby-2.1.0-preview2/bin/irb
retinalols-3:Sites russ$ irb
2.1.0dev :001 > require 'delegate'
 => true 
2.1.0dev :002 > 
2.1.0dev :003 >   class X < DelegateClass(Integer)
2.1.0dev :004?>     def initialize(value, name)
2.1.0dev :005?>         value = Integer(value)
2.1.0dev :006?>         @name = name
2.1.0dev :007?>         super(value)
2.1.0dev :008?>       end
2.1.0dev :009?>   end
 => :initialize 
2.1.0dev :010 > 
2.1.0dev :011 >   X.new(1, 'test')
ArgumentError: not delegated
    from /Users/russ/.rvm/rubies/ruby-2.1.0-preview2/lib/ruby/2.1.0/delegate.rb:384:in `__getobj__'
    from /Users/russ/.rvm/rubies/ruby-2.1.0-preview2/lib/ruby/2.1.0/delegate.rb:77:in `method_missing'
    from (irb):5:in `initialize'
    from (irb):11:in `new'
    from (irb):11
    from /Users/russ/.rvm/rubies/ruby-2.1.0-preview2/bin/irb:11:in `<main>'
2.1.0dev :012 > 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.