Ruby 1.8.0 Released
waieitch writes "A long-waited new version of the scripting language, Ruby 1.8.0 has just been released. You can download from here, and the changelog is available. With many new libraries, say dRuby, ERB, REXML, this version is doubled by 1.6.8 in size."
No more text.
This language is definitely worth a look. It's not just a python knock-off, as many have supposed -- it offers features python doesn't.
"He who would learn astronomy, and other recondite arts, let him go elsewhere. " -- John Calvin, commenting on Genesis 1
Apparently the poster isn't a native English speaker. Anyway, all he meant was that the tarball is about twice as big now. This is almost entirely due to the inclusion of more libs, not an increase in size of the Ruby core.
Here's the link to the changelog.
DNA is the ultimate spaghetti code.
If I'm not mistaken, Ruby is the first language to include built-in support for YAML!
Thanks to Matz for such a great language!
Don't forget some of the other unique uses of blocks, that make them very, very powerful.
They can be used in unique ways that are pretty darn useful. For instance, you can use them to create configuration blocks for objects, without cluttering the constructor.
A constructor aware of this can use this block to configure the object in ways that normally would require dozens of different constructors, with a relatively unambiguous syntax. Even better, defining those set functions for the configuration block also defines them as instance variables. 2 foe the price of one!With a little thought and use of Ruby's excellent security model, it's possible to even just dump a file into that block, and use the file as the configuration block!
Slashdot. It's Not For Common Sense
A good example of this is the lack of need for semicolons at the end of each line. Ruby has semicolons for statement separators, but you only need to use them when there are multiple statements on one line. For example:
Another example is that you don't have to use straight brackets to delimit arrays. You only must use them to clarify confusing situations.It's important to differentiate this attribute from the flexibility of the syntax. Ruby allows you to use, or not use, certain pieces of its syntax to help you adjust to it. For instance, when calling sending a message to an object, you need not use parenthesis to delimit the message parameters. In general there is a synonym for most every syntactic feature. One is the common usage (likeOne might be tempted to say that is what's wrong with Perl, and to a degree that's true. Ruby however, keeps its core syntax quite small. The synonyms exist for a clear and obvious purpose. Perl seems to lack that purpose, instead citing TIMTOWTDI.
Slashdot. It's Not For Common Sense
One of the most useful instances of blocks I've found, and the one that truly converted me to Ruby, is registering them as callbacks.
I was working on a program while learning Ruby where we wanted to filter an incoming stream of events and filter them out to handlers. Some events needed to be dispatched to multiple handlers, others could be ignored.
The traditional approach would be to modify Dispatcher (any capitalized noun will be a class in my example here) and add some filtering logic each time a new filter needed to be added. But with procs (which are real closures, not just anonymous code blocks), I can do this:
Of course, this example is trivial, but the I'll admit I've since learned a way to do this in Perl, but it's much cleaner and all in all elegant the Ruby way.
Jacob Fugal
(ps. apparently <ecode> doesn't preserve my indentation, sorry...)
Smalltalk is a language which manages to be expressive, but without the amount of syntax that Ruby has.
:= Regexp new: '[0-9.]+' .
:= File open: 'copyOfGeneral.txt' .
:= Dictionary new .
.
I'm a Smalltalk-er who likes Ruby for its Smalltalk-eyness.
After all, here are 5 lines of Ruby code that give the count of unique IP numbers listed from a webserver logfile which downloaded a particular file from the server
Ruby code:
anIpNum = Regexp.new(/[0-9.]+/)
aFile = File.open('D:/Savant/copyOfGeneral.txt')
aDicti onary = Hash.new
aFile.each_line { | line | aDictionary[line.slice(anIpNum)] = 1 if line.include?("plastic_1.1_lite-UMLtool-fw.exe") }
puts aDictionary.size
and the equivalent Smalltalk
anIpNum
aFile
aDictionary
aFile each:
[ | eachLine |
eachLine include: 'plastic'
ifTrue: [ aDictionary at: anIpNum put: 1 ]
]
aDictionary size
Of course, in Smalltalk-80 there isn't a standard Regexp class, so I'd have to find one.
But I hope you all agree that Ruby's syntax is not too far off Smalltalk's elegance in this example.
p.s. Apologies for the formatting, but until I selected 'Code', Slashdot's lameness filter kept rejecting this post...
Ruby is a cool language, but someone has to break down and document it. There is quite a bit of not-quite-current documentation, including a great online version of Programming Ruby , but the official library reference is for 1.6 and the language reference is for 1.4. The lack of current documentation for 1.8 raises doubts about the consistency of the language's behavior, especially its more Perlish, do-what-I-mean features.
You know, reading over the the information available for Perl 6, I get the idea that a lot of the improvements intended for Perl 6 were actually stolen from Ruby. As much as I love Perl, the OO implementation is a bolted-on, pain-in-the-ass kludge. Ruby's is an integral part of the language, and Ruby is a very nice language.