3 ms·
Hm. Obviously not as elegant, but I'm sure someone more versed with Ruby could do better. class Object def _ &block instance_eval &block
by SlyShy 17y ago
Hm. Obviously not as elegant, but I'm sure someone more versed with Ruby could do better.
class Object
def _ &block
instance_eval &block
end
end
s = "Hello"
s._ do
upcase!
chop._ do
downcase
end
end #=> "hell"
s #=> "HELLO"
Using { } for block syntax may be more appealing to some, as well.
- raganwald 17y agoI have done instance_eval-ish stuff in Ruby. There are some tricky bits when you do this, as it changes how methods with blocks behave when inside other methods with blocks. But I like the way you think!