'with' proposal

  • Thread starter Elias Athanasopoulos
  • Start date
E

Elias Athanasopoulos

Hello!

Wouldn't something like this be cool?

class Foo
def read
...
end
def dump
...
end
def is_empty?
...
end
end

f = Foo.new

with f do
read
dump
draw unless is_empty?
end

Regards,
 
E

Elias Athanasopoulos

irb(main):007:0> class Foo; def talk; puts "hi"; end; end
=> nil
irb(main):008:0> f = Foo.new
=> #<Foo:0x400b32a8>
irb(main):009:0> f.instance_eval do talk end
hi

:)

Uber nice! Thanx. :)

Regards,
 
D

Dan Doel

Further:

class Foo
def talk
puts "Hi."
end
end

def with(obj, &blk)
obj.instance_eval &blk
end

f = Foo.new

with f do
talk
end


- Dan
 
G

gabriele renzi

il Sun, 23 Nov 2003 03:26:38 +0900, Elias Athanasopoulos
Hello!

Wouldn't something like this be cool?
with f do
read
dump
draw unless is_empty?
end

this is a faq:

def with(obj, &blk)
obj.instance_eval &blk
end

with 10 do
puts to_s
puts methods
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,813
Members
47,357
Latest member
sitele8746

Latest Threads

Top