Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env ruby
- class A
- def foo(arg)
- false
- end
- def self.foo_maker(*args)
- args = args.flatten
- instance_eval "
- def foo(arg)
- #{args.inspect}.include?(arg)
- end
- "
- end
- end
- class B < A
- foo_maker :a, :b, :c # this fails, undefined method - but if foo_maker is << self, how do I get the instance?
- end
- a = A.new
- b = B.new
- puts a.foo(:a) # expected: false
- puts b.foo(:a) # expected: true, actual: false
- puts b.foo(:d) # expected: false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement