"Gtk::Window#show" notation

I am reading the tutorial in Ruby-gnome2 and I see:

“The third line calls Gtk::Window#show to display the window we just
created:”

to describe:

“window.show”

Please excuse my ignorance, but I do not know the use of the ‘#’
character here. I’ve searched around quite a bit. I see the syntax is
commonly used, but I cannot locate an explanation of it. The only
explanation I see for the ‘#’ character is that everything following is
a comment.

Can someone point me to documentation that describes the use of ‘#’
other than as the comment character? Or perhaps tell me what I should
have read before this tutorial?

Robert Plantz wrote:

Can someone point me to documentation that describes the use of ‘#’
other than as the comment character? Or perhaps tell me what I should
have read before this tutorial?

This is a convention. GtkWindow#show means “instance method ‘show’ in
the class GtkWindow”. I’ve seen it used heavily in Smalltalk-related
material, though the last time this topic came up (a year or so back?),
someone came up with a more detailed “etymology”. I’d tell you to check
the mailing list archives, except I’ve no idea myself what I’d begin to
search for…

David V.

Robert Plantz wrote:

Can someone point me to documentation that describes the use of ‘#’
other than as the comment character? Or perhaps tell me what I should
have read before this tutorial?

This may not apply, but:

a = “Huey”
b = “Louie”
c = “Dewey”

puts “#{a}, #{b}, and #{c} were out walking one day …”

So “#” serves at least one other purpose apart from its role as a
comment
delimiter.

On Mon, 23 Oct 2006 08:27:32 +0900, David V. wrote:

the mailing list archives, except I’ve no idea myself what I’d begin to
search for…

Note that ri accepts this notation to refer to a class name when you’re
asking for documentation (you may need to quote the whole thing in your
shell), but there is NO part of the Ruby language that accepts this
notation, nor do I really see much need.

To get an UnboundMethod object referring to the instance method ‘show’
in
the class ‘GtkWindow’, you use the code GtkWindow.instance_method(:show)
since the need for that in actual code pretty uncommon to begin with,
there’s no reall need for more concise notation.

–Ken

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs