Octothorpe
The #
symbol is called an octothorpe. You may see it referred to outside the context of Ruby as hash, pound, or even hashtag. We'll see the octothorpe show up in two very common ways throughout Ruby. Let's take a look at both.
Comment Syntax
Practically speaking Ruby has one primary way to write comments:
# this is a comment
# this is
# a
# multi-line
# comment
Technically, there is also the =begin
/=end
syntax for multi-line block comments, but you'll see it used pretty rarely.
Fun fact: the following is valid comment syntax in Ruby because of how the unicode character is encoded:
#️⃣ this is a valid comment
Indicating Instance Methods
The #
symbol is also used to indicate that a method is an instance method of that class.
For instance, the each
method on Array
is typically referred to as #each
or as Array#each
.
This helps distinguish instance methods from class methods (e.g. Array.new
).