On Tue, Apr 22, 2008 at 10:35 PM, Andres <andresgaragiola / gmail.com> wrote:
> Hi ruby list,
>
>  I=B4m a smalltalk developer and now i'm beginning with Ruby. I found
>  words like "puts" on the ruby syntax that i don=B4t 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"?

puts is a message.  The puts method is implemented in the Kernel
module which is included in the Object class.

In Ruby, in most cases the self pseudo-variable is not required, so

   puts
is equivalent to
  self.puts

At the top-level in ruby there is a singleton object which is bound to self=
.

>  A smalltalk code similar to ruby code
>   >> puts "Hello world"
>
>  is
>
>   Transcript show: 'Hello world'

Kernel#puts writes its output to stdout.  Other Ruby classes also
implement puts, for example IO#puts writes the output to receiver, so
you can send puts to, say a file object, which is a better analog to
Smalltalk's Transcript.show:

>  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 =3D=3D 0
>             return 1
>        else
>             return self * ((self-1).factorial)
>        end
>    end
>  end
>
>  in smalltalk
>
>   factorial
>
>    ^self =3D 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=B4t
>  understand like it works in ruby, when is implemented the message "if
>  else"?

This is different in Smalltalk and Ruby.  In Ruby control flow is done
via compiled code control transfer rather than message send.

Of course most Smalltalk compilers don't really implement
ifTrue:ifFalse: and similar methods via message sending either,
instead they compile such 'messages' to branching byte codes, perhaps
with a fallback if the 'receiver' isn't a boolean.  There are other
areas where Smalltalk implementations 'cheat', for example, sending
value to a block often doesn't really send a message, and some
Smaltalks have little head scratching puzzles such as a value method
in Block which looks like

value
   ^self.value

which is only there in case someone does something like

    aBlock perform: #value

I do know a bit about Smalltalk, or at least I used to, I was a
founding member, and  Secretary of X3J20, the ANSI Smalltalk standards
commitee.

--=20
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/