I’m not sure any of the previous answers will help you learn ruby,
hopefully this is a better explanation to why this error occurred.
Your original statement:
pin_number == @pin ? puts “Balance: $#{@balance}.” : pin_error
the ruby interpreter thinks you are doing this
if pin_number == @pin
puts “Balance: $#{balance}” : pin_error
else
since you didn’t include the parentheses it tries to pass the remaining
parts of the short-hand conditional into the puts function
if you try calling:
puts “Balance: $#{@balance}” : pin_error
you will see a similar error message.
By putting the parentheses around “Balance: $#{@balance}” you are
telling
the ruby interpreter that you only want that argument passed into the
puts
function.
Hopefully that sheds some more light on the error.
I like the second version
if pin_number == @pin
puts(“Balance: $#{@balance}.”)
else
pin_error
end
because in the future if we want to add more instructions it will be
easily to insert it.
I think of the code as 5 dimensions image(1) imperative (instruction
under instruction - do this then do that)(2) one line expression (long
horizontal)(3) nested (structures inside structures)(4) pointers (jump
up/down or forward/backward)(5) Abstraction (Files, Modules, Classes,
Functions,…etc)
selecting the right dimension for your code is an art
Also some guidelines would help in the process
since you didn't include the
parentheses it tries to pass the remaining parts of the
short-hand conditional into the puts function
if you try calling:
?? ?? ??puts "Balance: $#{@balance}" : pin_error
you will see a similar error message.??
By putting the parentheses around "Balance: $#{@balance}"
you are telling the ruby interpreter that you only want that
argument passed into the puts function.
Hopefully that sheds some more light on the error.
-Cameron
On Wed, Nov 19, 2014 at 9:09 AM,
Roelof W. <[email protected]>
wrote: