Created
August 9, 2015 14:47
-
-
Save Sylvain303/55c330ac6bf113711286 to your computer and use it in GitHub Desktop.
ruby delegate DelegateClass removing global scope
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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