Skip to content

Instantly share code, notes, and snippets.

@Sylvain303
Created August 9, 2015 14:47
Show Gist options
  • Save Sylvain303/55c330ac6bf113711286 to your computer and use it in GitHub Desktop.
Save Sylvain303/55c330ac6bf113711286 to your computer and use it in GitHub Desktop.
ruby delegate DelegateClass removing global scope
require 'delegate'
def test_that?(n)
return n < 12
end
class MyID < DelegateClass(Integer)
def initialize(num)
@small = false
if test_that?(num)
@small = true
end
super(num)
end
def small?
@small
end
end
puts "small" if test_that?(4)
id = MyID.new(11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment