Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Alternatives to sed + awk



On 11 March 2011 03:47, Stephen J. Turnbull <stephen@example.com> wrote:

> I like functions as first class objects a lot.

I do as well in Python and C (heh heh); it just turns out that you
never need them in Ruby. I actually don't use functions at all in my
Ruby code. Everything is a class or instance method, so it doesn't
make sense to pass those around. What one usually does is passes
around a symbol, then does a target_object.send(method, ...) to invoke
it. This makes sense if you take the OOP "messages and receivers"
stuff literally.

When you need an anonymous function in Ruby not bound to a class or
object, you can use a Proc object:

my_func = Proc.new do |*args|
  puts "Golly gee, I was called with #{args.size} arguments!"
end

my_func.call 1, :two, 'three', 4.0

> I find the Python convention that identifiers named with leading
> underscores are private an equally good signal in practice.

You mean the Perl convention? ;-P

-- 
Cheers,
Josh


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links