Christopher Dicely
5/23/2008 2:07:00 AM
On Thu, May 22, 2008 at 6:20 PM, APNelson.L <APNelson.L@gmail.com> wrote:
> I was just wondering what the benefit would be of creating a block
> that can be called rather than defining a method. Here is an example:
>
> def puts_time(x)
> puts x
> end
>
> instead of...
>
> puts_time = lambda { |x| puts x }
>
> personally I see no reason to create a block like this instead of a
> method.
You can pass a lambda or proc to another method, which you can't
exactly do with a method (you can get most of the same effect by
passing the method on which the method is defined and the method name,
and calling the method that way.) But, yes, more generally OOP and
functional programming are essentially different techniques which
often can be used to save the same ends, so often having access to
both techniques may seem redundant.