Over a million developers have joined DZone.

Nested Methods In Ruby

·
Source: igrigorik [twitter.com]
... ruby's syntax allows for nested methods:

def a; def b; :b; end; b; end; a 
#=> :b


Here's another example:

def a2
  def c
    "hello"
  end
  c
end

a2
#=> "hello" 


Note: Even though the method is nested it still has the same scope as a non-nested method.
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}