If you run foo, you get hell outputted, not ell, even though the regex match in bar ran temporally after the one in foo.

]]>By: Arthurhttp://yehudakatz.com/2010/02/25/rubys-implementation-does-not-define-its-semantics/comment-page-1/#comment-25297
Thu, 03 May 2012 18:34:03 +0000http://yehudakatz.com/?p=443#comment-25297It may be a bit late to reply to this blog post, but regarding your latest example, aren’t $-prefixed variables global in Ruby? In this case, the $ regexp variables are simply global variables put to new values every time a regexp is executed.
That makes the mental model and the implementation both simpler by the way.
]]>By: Bogdan Gusievhttp://yehudakatz.com/2010/02/25/rubys-implementation-does-not-define-its-semantics/comment-page-1/#comment-18677
Sun, 11 Apr 2010 11:14:23 +0000http://yehudakatz.com/?p=443#comment-18677Could you please explain how does #block_given? works?
I am having no idea how it can detect the block without accepting any argument by itself.

]]>By: Sebastian Güntherhttp://yehudakatz.com/2010/02/25/rubys-implementation-does-not-define-its-semantics/comment-page-1/#comment-18512
Thu, 04 Mar 2010 00:40:36 +0000http://yehudakatz.com/?p=443#comment-18512Mental model are a good metaphor to understand the semantic modifiability. But what is the “true source” for this model? MRI? JRuby? Rubinus? Or should we skip this part and just form our own model according to Rubys language specification project.
]]>By: Avdihttp://yehudakatz.com/2010/02/25/rubys-implementation-does-not-define-its-semantics/comment-page-1/#comment-18498
Mon, 01 Mar 2010 18:07:56 +0000http://yehudakatz.com/?p=443#comment-18498Yehuda, I compared your mental model to the one in the draft ISO spec. Details here: http://avdi.org/devblog/2010/03/01/getting-pedantic-about-ruby-semantics/ Short version: your model differs from the spec; but so, apparently, does MRI.
]]>By: banisterfiendhttp://yehudakatz.com/2010/02/25/rubys-implementation-does-not-define-its-semantics/comment-page-1/#comment-18489
Sat, 27 Feb 2010 11:59:51 +0000http://yehudakatz.com/?p=443#comment-18489@Justice, actually in the case of ordinary Ruby classes (T_CLASS) metaclasses are not created lazily but at class creation time (at least in MRI and YARV).
]]>By: Justicehttp://yehudakatz.com/2010/02/25/rubys-implementation-does-not-define-its-semantics/comment-page-1/#comment-18487
Fri, 26 Feb 2010 19:32:22 +0000http://yehudakatz.com/?p=443#comment-18487Not only it just an optimization that metaclasses are lazily created, it is also a requirement for implementation.

Given every object has its own metaclass
And every metaclass is an object
And metaclasses are eagerly created #hypothetically
When a Ruby program starts up
Then it runs out of memory immediately

I think a point also worth making (again, because I believe you’ve already mentioned this elsewhere) is that Procs are just objects in Ruby, and methods can take them as regular arguments also:

class Greeter
def call; puts “Hello”; end
end

def foo(thingy)
thingy.call
end

foo(Proc.new {puts “Hello”})
foo(Greeter.new)

In both cases, the result is exactly the same — Proc are just objects. This feature lets Rack support applications that are just Procs as well as objects that respond to call without any special logic, which is extremely powerful.