'with' proposal

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,

···


University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky

Hi –

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

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

:slight_smile:

David

···

On Sun, 23 Nov 2003, Elias Athanasopoulos wrote:


David A. Black
dblack@wobblini.net

this is a faq:

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

with 10 do
puts to_s
puts methods
end

···

il Sun, 23 Nov 2003 03:26:38 +0900, Elias Athanasopoulos elathan@phys.uoa.gr ha scritto::

Hello!

Wouldn’t something like this be cool?

with f do
read
dump
draw unless is_empty?
end

Uber nice! Thanx. :slight_smile:

Regards,

···

On Sun, Nov 23, 2003 at 03:30:18AM +0900, David A. Black wrote:

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

:slight_smile:


University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky

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