Newbie question about the # symbol

ruby

Newbie question about the # symbol

Postby Justin » Wed, 15 Mar 2006 22:20:35 GMT

I have just started learning Ruby and I am going through as much 
documentation as I can find.  The only question that I cannot seem to 
find an answer to concerns the use of the # symbol when referring to 
methods (I think I've seen it used to refer to both class and instance 
methods).

Here is an example:
 http://www.**--****.com/ #IO.select

On the above page there is a link to "Kernel#select" which is a class 
method.

and here: 
 http://www.**--****.com/ #Object.is_a_qm

There is a link to "Object#kind_of?" which is an instance method. 
Clearly the purpose of the hash mark has another purpose.  Anyone know 
what document explains this?

Thanks!
Justin

-- 
Posted via  http://www.**--****.com/ 



Re: Newbie question about the # symbol

Postby rmagick@gmail.com » Wed, 15 Mar 2006 22:29:08 GMT

# is not Ruby syntax, it's a documentation convention that denotes
"instance method," as in "kind_of? is an instance method of Object" as
opposed to "class method," which is distinguished by a period between
the class name and the method name.


Re: Newbie question about the # symbol

Postby Mike Fletcher » Wed, 15 Mar 2006 22:36:10 GMT




The notation's explained in the preface:

 http://www.**--****.com/ #S10

Basically it means "the instance method kind_of? implemented by the 
Object class"; not really syntax, but convention for discussing Ruby. 
The 'ri' utility uses something similar.

-- 
Posted via  http://www.**--****.com/ 



Re: Newbie question about the # symbol

Postby James Edward Gray II » Wed, 15 Mar 2006 22:44:12 GMT




Class methods are also often shown as follows:

   MyClass::class_method

ri even seems to favor this notation.

James Edward Gray II



Re: Newbie question about the # symbol

Postby James Edward Gray II » Wed, 15 Mar 2006 22:45:12 GMT




Actually, all the Kernel methods are instance methods, so they can be  
mixed into Object.

James Edward Gray II



Re: Newbie question about the # symbol

Postby Justin » Wed, 15 Mar 2006 22:46:56 GMT



Ahh ok, excellent thank you that was confusing me quite a bit.

-- 
Posted via  http://www.**--****.com/ 



Similar Threads:

1.newbie question: symbol to fully qualify a method: #, ::, .

I'm a newbie.  I'm going through the ruby documentation and I noticed
there's 3 different separators (#, ::, .) used to fully qualify a
method in a class or module.

i.e.
MyClass.myproc
MyClass#myproc
MyClass::myproc

What's the difference?

2.Ruby Newbie: What if @ symbol is not used?

Hello Everyone,

Pardon this newbie question.

What if the @ symbol is not used before creating new variable names
inside of methods?

Thanks,

Todd

3.Newbie: Symbol as array index error

4.Newbie question: Simple Ruby Date Question

Hi everyone

I am playing around with ruby. And as a Java developer I wrote this
method to get me the weekdays of a month:
########
	def weekdays(month)
		current = Date.new(month.year,month.month,01)
		result = Array.new
		while (current.month == month.month)
			if(current.wday != 0 && current.wday != 6)
				result.push(current)
			end
			current += 1
		end
		return result
	end
########

What would be a nice ruby way to write this?

5.Question about symbols

6. question about symbol naming convention

7. Question about NUM2LONG, symbols

8. Symbols & yaml (was SOT (slightly offtopic): General OOP question)



Return to ruby

 

Who is online

Users browsing this forum: No registered users and 3 guest