Re: "with" statement
by Pete Elmore other posts by this author
Oct 23 2007 12:10PM messages near this date
Re: "with" statement
|
Re: "with" statement
On 21/10/2007, Dan Yoder <dan@[...].com> wrote:
> module Kernel
> def with(object,&block)
> object.instance_eval &block
> end
> end
>
> with([1,2,3]) { length } # => 3
You could even do something like this:
module Kernel
def with_block(*args, &block)
send(*args) { |obj| obj.instance_eval &block }
end
end
['asdf', 'jkl', 'semicolon'].with_block(:map) { length } # => [4, 3, 9]
That would allow something like this:
<% with_block(:form_for, :user, @user) { %>
<%= text_field :name %>
<%= text_field :email %>
<%= password_field :password %>
<% } %>
It may or may not be useful, but it's fun.
Thread:
Perry Smith
Dan Yoder
Pete Elmore
Randy Kramer
Giles Bowkett
Robert Klemme
Giles Bowkett
Stefan Rusterholz
Yossef Mendelssohn
Perry Smith
David A. Black
Robert Dober
Stephane Wirtel
|