# Object.object.method()

**URL:** <https://www.ruby-forum.com/t/object-object-method/195943>\
**Category:** Ruby\
**Created:** [October 3, 2010, 5:29pm UTC](https://www.ruby-forum.com/t/object-object-method/195943 "2010-10-03T17:29:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![withaspoon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/db5fbb/32.png) [@withaspoon](https://www.ruby-forum.com/u/withaspoon)\
**Post date:** [October 3, 2010, 5:29pm UTC](https://www.ruby-forum.com/t/object-object-method/195943/1 "2010-10-03T17:29:38Z")

</div>

Hello, obviously it’s a time for a noobie question. What the following  
statement means?

Object.object.method()

Sample code:

window = Gtk::Window.new(Gtk::Window::TOPLEVEL)  
area = Gtk::DrawingArea.new()  
area.window.set\_cursor(Gdk::Cursor.new(Gdk::Cursor::PENCIL))

I’m confused. Can anyone enlight me?

Thanks.

---

<div class="post-metadata">

**Author:** ![withaspoon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/db5fbb/32.png) [@withaspoon](https://www.ruby-forum.com/u/withaspoon)\
**Post date:** [October 3, 2010, 5:56pm UTC](https://www.ruby-forum.com/t/object-object-method/195943/2 "2010-10-03T17:56:00Z")

</div>

On Sun, Oct 3, 2010 at 11:29 AM, Johan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hello, obviously it’s a time for a noobie question. What the following  
> statement means?
> 
> Object.object.method()  
> Sample code:
> 
> window = Gtk::Window.new(Gtk:🪟:TOPLEVEL)  
> area = Gtk::DrawingArea.new()  
> area.window.set\_cursor(Gdk::Cursor.new(Gdk::Cursor::PENCIL))

I assume you are talking about that last line.

area.window.set\_cursor(dk::Cursor::PENCIL)

What that means is:

1. send the message window to the object referenced by the variable  
area (which in the above code would be an instance of  
Gtk::DrawingArea. This will return a result object.

2. send the result object which was returned in step 1 the message  
set\_cursor with the argument dk::Cursor::PENCIL

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Github: [rubyredrick (Rick DeNatale) · GitHub](http://github.com/rubyredrick)  
Twitter: @RickDeNatale  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![withaspoon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/db5fbb/32.png) [@withaspoon](https://www.ruby-forum.com/u/withaspoon)\
**Post date:** [October 4, 2010, 11:50am UTC](https://www.ruby-forum.com/t/object-object-method/195943/3 "2010-10-04T11:50:25Z")

</div>

2010/10/3 Johan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I’m confused. Can anyone enlight me?

To complete Rick’s answer, the “window” in the last line has  
(normally) _nothing_ to do with your window variable. Ruby sees that  
you are trying to talk to the object “area” (because of the dot) so it  
politely ask “area” if it has a method named “window” (which I assume  
it has). You could try

fenetre = Gtk::Window.new(Gtk:🪟:TOPLEVEL)  
area = Gtk::DrawingArea.new()  
area.window.set\_cursor(Gdk::Cursor.new(Gdk::Cursor::PENCIL))

it should still work (assuming you change all the other occurence of  
_variable_ “window” into “fenetre”)

On the contrary, the code

fenetre = Gtk::Window.new(Gtk:🪟:TOPLEVEL)  
area = Gtk::DrawingArea.new()  
area.fenetre.set\_cursor(Gdk::Cursor.new(Gdk::Cursor::PENCIL))

should not work: ruby should complain with a “NoMethodError”

Cheers,

---

<div class="post-metadata">

**Author:** ![withaspoon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/db5fbb/32.png) [@withaspoon](https://www.ruby-forum.com/u/withaspoon)\
**Post date:** [October 4, 2010, 12:12pm UTC](https://www.ruby-forum.com/t/object-object-method/195943/4 "2010-10-04T12:12:38Z")

</div>

Rick Denatale wrote:

> I assume you are talking about that last line.
> 
> area.window.set\_cursor(dk::Cursor::PENCIL)
> 
> What that means is:
> 
> 1. send the message window to the object referenced by the variable  
> area (which in the above code would be an instance of  
> Gtk::DrawingArea. This will return a result object.
> 
> 2. send the result object which was returned in step 1 the message  
> set\_cursor with the argument dk::Cursor::PENCIL

Or to put it another way, it’s the same as this:

tmp = area.window  
tmp.set\_cursor(dk::Cursor::PENCIL)

---

<div class="post-metadata">

**Author:** ![withaspoon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/db5fbb/32.png) [@withaspoon](https://www.ruby-forum.com/u/withaspoon)\
**Post date:** [October 4, 2010, 3:10pm UTC](https://www.ruby-forum.com/t/object-object-method/195943/5 "2010-10-04T15:10:36Z")

</div>

Alors! GTK ne parle pas français?

And in Ruby 1.9 you could spell it properly as fenêtre, but it would  
still cause a “No Method” error.

On Mon, Oct 4, 2010 at 5:49 AM, Jean-Julien F.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > area.window.set\_cursor(Gdk::Cursor.new(Gdk::Cursor::PENCIL))  
> > area = Gtk::DrawingArea.new()
> 
> should not work: ruby should complain with a “NoMethodError”
> 
> Cheers,
> 
> –  
> JJ Fleck  
> PCSI1 Lycée Kléber

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Github: [rubyredrick (Rick DeNatale) · GitHub](http://github.com/rubyredrick)  
Twitter: @RickDeNatale  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![withaspoon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/db5fbb/32.png) [@withaspoon](https://www.ruby-forum.com/u/withaspoon)\
**Post date:** [October 4, 2010, 9:54pm UTC](https://www.ruby-forum.com/t/object-object-method/195943/6 "2010-10-04T21:54:30Z")

</div>

2010/10/4 Rick DeNatale [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Alors! GTK ne parle pas français?

What a shame, isn’t it ? ;o)

I almost wrote Fenster to avoid the use of ê but for one my german is  
not even close to what I was able to do in highshool (and I didn’t do  
much at that time…) and secondly I thought that the use of the  
uppercase (although autorised when defining a method) would be even  
more misleading on that matter.

Cheers !
