JACK M JACK M - 4 years ago 97
Ruby Question

What is the # (sharp, number, pound, hash) sign used for in Ruby?

What are the various meanings of the Ruby sharp/number sign/pound/hash(#) symbol

How many contexts does the symbol

in Ruby have ?

I know that #` represents comment

# a comment

or 'convert to the value':

i = 1
print "#{i}" # simple example

However I also see some Ruby docs describe built-in methods like these:


Why do they describe the same thing using 2 different symbols ?
I am new in Ruby. Thanks

Answer Source

This is how instance method described:


So you can:

a = Array.new(2)
 => [nil, nil]
 => [42, 42]

This is how class method described:


s = String.new('abc')
 => "abc"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download