-1

Here is the example:

def container(number=:FIXME)  
  "bottles"
end

Excerpt From: Sandi Metz, Katrina Owen. “99 Bottles of OOP.” iBooks.

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
Ekaitz Hernandez Troyas
  • 1,147
  • 2
  • 11
  • 18
  • 1
    The sentence below that code block in the book says: _"The above code takes an argument named `number`, which it defaults to the symbol `:FIXME`"_. It then explains _why_ a symbol is used as the default value. – Stefan Nov 11 '16 at 11:03
  • I think [that](http://stackoverflow.com/questions/6337897/what-is-the-colon-operator-in-ruby) question is different because is not talking about constants and symbols in ruby. – Ekaitz Hernandez Troyas Nov 11 '16 at 11:49

1 Answers1

3

It is not a constant, it is a Symbol object.

FIXME = 1
FIXME.class
#=> Fixnum
Object.const_defined?('FIXME')
#=> true
:FIXME.class
#=> Symbol
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
  • And why is using uppercases I thought the convention in Ruby is that if variable has uppercases is a constant. It was confusing for me because I have never seen a symbol with uppercases. – Ekaitz Hernandez Troyas Nov 11 '16 at 11:33
  • 1
    @EkaitzHernandezTroyas I think you will find an answer reading further - Sandi Matz is one of the greatest Ruby minds and believe me, if she creates a symbol in capital letters she has a good reason for that ;) – Andrey Deineko Nov 11 '16 at 11:36
  • Yes this is the reason that I am reading the book but I think she doesn't explain why is using uppercases and from my totally ignorance I think is a bad practice. – Ekaitz Hernandez Troyas Nov 11 '16 at 11:39
  • @EkaitzHernandezTroyas As Stefan commented under your question, it might very well be that you did not yet reach the moment where she explain it. I haven't read the book yet, so can't tell why she did so – Andrey Deineko Nov 11 '16 at 12:01
  • 1
    @EkaitzHernandezTroyas an uppercase symbol is used because it stands out. It is meant to be replaced later on. Quoting again from the paragraph following the code block: _"This default is a temporary shim whose purpose is to enable a step-by-step refactoring. Once the refactor is complete, the default should be removed. Setting it to a value like :FIXME will help you remember to do this clean-up."_ – Stefan Nov 11 '16 at 12:36