Hi ruby list,
I´m a smalltalk developer and now i’m beginning with Ruby. I found
words like “puts” on the ruby syntax that i don´t understand.
The basic object paradigm formula is “receiver + message”, an emisor
send a message to a receiver.
Is puts a message? if the answer is true, then what is the receiver?
and when is “puts” implemented? if the answer is false, then What is
“puts”?
A smalltalk code similar to ruby code
puts “Hello world”
is
Transcript show: ‘Hello world’
when “Transcript” is a global variable and the receiver of the message
#show: and ‘Hello world’ is an argument of the message.
other case is the bifurcation example
class Integer
def factorial
if self == 0
return 1
else
return self * ((self-1).factorial)
end
end
end
in smalltalk
factorial
^self = 0 ifTrue: [ 1 ] ifFalse: [ self * ((self-1) factorial) ]
the message #ifTrue:ifFalse: is implemented in the class Boolean and
in his subclasses, and receive two block argmuments, the behavior if
the boolean is true and the behavior if the boolean is false. I don´t
understand like it works in ruby, when is implemented the message “if
else”?
Thanks
Andrés