# Meta: who is the reciever?

**URL:** <https://www.ruby-forum.com/t/meta-who-is-the-reciever/122769>\
**Category:** Ruby\
**Created:** [December 11, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/meta-who-is-the-reciever/122769 "2007-12-11T23:06:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bogea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ec9cab/32.png) [@bogea](https://www.ruby-forum.com/u/bogea)\
**Post date:** [December 11, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/meta-who-is-the-reciever/122769/1 "2007-12-11T23:06:58Z")

</div>

Hi guys,  
first sorry my poor english. I’m a spanish speaker from argentina  
seing a video-conf from Dave T. on metaprogramming I rose these  
questions:  
who is the reciever? where are stored the method definitions?

* * *

class Dave  
class \<\< self  
def hi  
puts 123  
end  
def self.hi  
puts 456  
end  
end

def self.call\_hi\_low  
hi  
end

def self.call\_hi\_up  
class \<\< self  
hi  
end  
end  
end

Dave.call\_hi\_low #=\>123  
Dave.call\_hi\_up #=\>456

---

<div class="post-metadata">

**Author:** ![bogea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ec9cab/32.png) [@bogea](https://www.ruby-forum.com/u/bogea)\
**Post date:** [December 12, 2007, 7:26pm UTC](https://www.ruby-forum.com/t/meta-who-is-the-reciever/122769/2 "2007-12-12T19:26:37Z")

</div>

Take a look:

class Object

# Just to access the metaclass

def metaclass  
class \<\< self; self; end  
end

end

class Foo

class \<\< self # Inside the metaclass

```
def a # A: class method of Foo or method of the Foo's metaclass
  "Class method";
end

def self.b # B: class method of the metaclass, or method of the

```

metaclass of Foo’s metaclass  
“Class method of the metaclass”;  
end

end

def self.c # C: same as A  
“Class method”;  
end

def d # D: instance method  
“Instance method”;  
end

def self.e # E: yet another example of A and C  
class \<\< self # Inside the metaclass of Foo, here we can call  
methods  
like B  
b;  
end  
end

end

[“Foo.c”, “Foo.metaclass.b”, “Foo.c”, “Foo.new.d”, “Foo.e”].each do  
|code|  
puts “#{code} #=\> #{eval(code)}”;  
end

---

<div class="post-metadata">

**Author:** ![bogea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ec9cab/32.png) [@bogea](https://www.ruby-forum.com/u/bogea)\
**Post date:** [December 12, 2007, 8:49pm UTC](https://www.ruby-forum.com/t/meta-who-is-the-reciever/122769/3 "2007-12-12T20:49:23Z")

</div>

Will produce:

Foo.c #=\> Class method  
Foo.metaclass.b #=\> Class method of the metaclass  
Foo.c #=\> Class method  
Foo.new.d #=\> Instance method  
Foo.e #=\> Class method of the metaclass

---

<div class="post-metadata">

**Author:** ![bogea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ec9cab/32.png) [@bogea](https://www.ruby-forum.com/u/bogea)\
**Post date:** [December 12, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/meta-who-is-the-reciever/122769/4 "2007-12-12T22:50:08Z")

</div>

Thanks Bernardo  
still a bit confusing for me but you provided enough working material to  
analyze  
looks like a chain: a method of the metaclass of the Foo’s metaclass

Bernardo Rufino wrote:

> Will produce:
> 
> Foo.c #=\> Class method  
> Foo.metaclass.b #=\> Class method of the metaclass  
> Foo.c #=\> Class method  
> Foo.new.d #=\> Instance method  
> Foo.e #=\> Class method of the metaclass
