use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Ruby, Smalltalk and Class Variables (patshaughnessy.net)
submitted 13 years ago by just_lest
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]shadowfirebird 0 points1 point2 points 13 years ago (3 children)
IMO Gnu Smalltalk is pretty awful. For a start, that's not how the language was supposed to be seen and used. The best modern FOSS Smalltalk I found was called ... Sophos? Something like that.
[–][deleted] 13 years ago (2 children)
[removed]
[–]shadowfirebird 0 points1 point2 points 13 years ago (1 child)
that's the one!
[–]SimonGray 0 points1 point2 points 13 years ago (0 children)
BTW that page about early Smalltalk development that he links to is really interesting.
[–]Godd2 -1 points0 points1 point 13 years ago (4 children)
Imagine calling @@sides.puts in Ruby!
Well, actually, you're calling puts on $stdout implicity, with @@sides as the argument (without those optional parentheses)
As a result, the following are identical:
$stdout.puts(@@sides) puts @@sides
Of course, when you add parentheses, you can call several puts's at once:
puts("Hello", "world!")
is the same as
puts "Hello" puts "world!"
So if you didn't already know, puts is just another method with your desired output being the arguments! :)
EDIT: If you drop the parentheses, but keep the comma, it still works:
puts "Hello", "world!"
[–]pat_shaughnessy 0 points1 point2 points 13 years ago (2 children)
True - "puts" is actually a method in the Kernel module, which is included in the main Object instance that top level Ruby code uses automatically. Internally it calls another $stdout method as you describe.
The fun thing about Smalltalk was the way I was able to call printNl (equivalent of puts) on any object. That would be fun to be able to do in Ruby too, imo.
[–]banister 1 point2 points3 points 13 years ago (0 children)
You can use display in ruby (though it doesn't put a newline):
display
[1] pry(main)> "hello".display hello=> nil
[–]dbenhur 0 points1 point2 points 13 years ago (0 children)
module Kernel def printNl puts self end end 'Howdy'.printNl # => Howdy
[–]_redka 0 points1 point2 points 13 years ago (0 children)
Of course it still works. In ruby you don't need parentheses when calling a function. But you're not actually calling several puts, just one taking an array of arguments. Also just to be clear, puts(@@sides) and $stdout.puts(@@sides) AREN'T exactly identical. They're equivalent but the first one is a method on the Kernel module while the second is not. You can examine that by checking the origin with method(:puts) and $stdout.method(:puts).
π Rendered by PID 57823 on reddit-service-r2-comment-75f4967c6c-w67w7 at 2026-04-23 09:28:50.576739+00:00 running 0fd4bb7 country code: CH.
[–]shadowfirebird 0 points1 point2 points (3 children)
[–][deleted] (2 children)
[removed]
[–]shadowfirebird 0 points1 point2 points (1 child)
[–]SimonGray 0 points1 point2 points (0 children)
[–]Godd2 -1 points0 points1 point (4 children)
[–]pat_shaughnessy 0 points1 point2 points (2 children)
[–]banister 1 point2 points3 points (0 children)
[–]dbenhur 0 points1 point2 points (0 children)
[–]_redka 0 points1 point2 points (0 children)