I have code such as this:
foo.bar
foo.baz(1)
foo.bagaloo('didoo')
instead i want to write it like this:
with (foo) do
bar
baz(1)
bagaloo('didoo')
end
how?
···
_____________________
Bret Pettichord
www.pettichord.com
I have code such as this:
foo.bar
foo.baz(1)
foo.bagaloo('didoo')
instead i want to write it like this:
with (foo) do
bar
baz(1)
bagaloo('didoo')
end
how?
_____________________
Bret Pettichord
www.pettichord.com
Bret Pettichord wrote:
how?
foo.instance_eval do
bar
baz(1)
bagaloo('didoo')
end
--
Florian Frank
Note that this won't work if you try to use assignment, because that
will be interpreted as a local variable. Better:
module Kernel
def with(obj)
yield self if block_given?
end
end
with longfooname do |f|
f.bar
f.baz(1)
f.bagaloo('didoo')
end
-austin
On Sat, 29 Jan 2005 07:29:59 +0900, Florian Frank <flori@nixe.ping.de> wrote:
Bret Pettichord wrote:
> how?
foo.instance_eval do
bar
baz(1)
bagaloo('didoo')
end
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca
Austin Ziegler wrote:
Note that this won't work if you try to use assignment, because that
will be interpreted as a local variable.
True. In this case 'self' could be used:
foo.instance_eval do
self.quux = true
end
If assignment methods haven't yet been defined in a class definition, the same problem occurs.
Better:
module Kernel
def with(obj)
yield self if block_given?
end
endwith longfooname do |f|
f.bar
f.baz(1)
f.bagaloo('didoo')
end-austin
Well, than you could do f = longfooname at the beginning as well. ![]()
--
Florian Frank