On Sat, 20 Jan 2001, Christian wrote:

> 
> > Josh Stern comments someone else comment about Ruby's first-class
> > objects:
> [snip]
> > I'd like to note that Ruby has Method class. You can check it's
> > workings from
> >
> >    http://www.rubycentral.com/ref/ref_c_object.html#method
> >
> >    - Aleksi
> 
> Oh, I'm going to hate myself for this.

Don't. Nice comments. Maybe too much babble for my liking, makes it
hard to extract the point you're having, but ok.

> A small, seemingly inconsequential aspect of Method is that it needs an
> Object to use.

Yep. I pondered that too, but it's actually quite natural.

> Sorry, this is bad. In general, not all functions are methods. Some problems
> do not require a context. Witness 'sort'. I am not changing the rules
> here -- I complained that Ruby does not have first-class functions. A method
> is not a function.

That's true. I was approximating a little.

You're right. Ruby does not have first-class functions. But to start with that Ruby should have functions first. And there's none. I'd guess that's a design issue, and matz has thought this a while before choosing the current way.

But is Ruby really missing something vital here? Please consider the following code:

  def foo
    # do something
    puts "foo"
  end

  foo()

How would you write that with a language with functions? Um..let me guess. In a same way? So where's the catch?

The thing is, there's a context (or a scope) for everything in Ruby. This one has it too. And it's named top-level. So the call foo() is actually self.foo() like any other method call.

Thus, there's no need to have functions. When you write function-like-methods it's like you're writing functions. When you use them, it's like functions. So the example above could be enlarged to have first-class "functions":

  m = method(:foo)
  m.call #=> foo() -> "foo"

> What it comes down to is the fact that everything in Ruby is an Object. Now,
> in the 80's and 90's this seemed a Good Thing. Is this true?

I like objects more now than during 90's. I have no problems with everything's an Object. I have much problems with "no, there's no need to have this as an object too". I'm fixing one of those right now, of Ruby, in Ruby.

> It would change the landscape of the language however.

You have lot of remarks or assertions with no back up. I hope this one was just waiting for explanation.

Ruby might have different landscape. In what way, and is it to the good direction or not, I can't say. For me, it's definitely looking most of the time just like it was in other OO languages, and then there's some room to bend if needed.

   - Aleksi