Syntactic Sugar…

 May 27, 2008

Was reading this post about Groovy syntactic sugar… closures and ++ operator are nice… but you could open up Hash and Array to get the other stuff.


# working with hashes
class Hash
  def method_missing(name, *args)
    fetch(name) if has_key?(name) or nil
  end
end
user = {:save => true, :destroy => false}
puts "--hashes"
puts "save? : #{user.save}"
puts "destroy? : #{user.destroy}"

# working with arrays
class Array
  def method_missing(name, *args)
    collect {|i| i.send(name)}
  end
end
puts "--upcase"
puts ["Mike", "McKinney"].upcase

# fetching attributes of arrays
name1 = {:first_name => "Mike", :last_name => "McKinney"}
name2 = {:first_name => "Bo", :last_name => "Diddley"}
names = [name1, name2]

puts "–first names "
puts names.first_name
puts "–last names "
puts names.last_name
puts "–middle names "
puts names.middle_name

Of course you would want to look a little closer at the implications this type of patch would have on your code, but it’s sure nice how flexible ruby can be.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Digg
  • Reddit
  • DZone

JavaOne ‘08 - Script Bowl apps for JRuby released

 May 13, 2008

This year’s JavaOne had an interesting competition… the Script Bowl.  Pitting 4 different languages (Groovy, Scala, Jython & JRuby) on the JVM against each other in three different categories.  (Rich Client Application, Web Application and an Open event)  Check the results here on Rags’ blog.

Headius just posted the JRuby Script Bowl artifacts for your viewing pleasure.  Anyone know if the other languages have posted their apps/code?

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Digg
  • Reddit
  • DZone

Re: RSS Feeds for Subversion

 May 6, 2008

I was reading a friend’s blog post about RSS feeds for Subversion repositories earlier… he couldn’t find anything that was not written in a scripting language which he has no access to in his environment… he needed a Java based solution.  He solved his problem with a war.  I came back to this after dinner (and a few glasses of wine) and decided to show him another way to solve this problem on the JVM… (you knew it was coming Matt.)

Assuming you already have JRuby setup (of course you do), we’ll do the following to get the one gem we’ll need:


> jruby -S gem install rscm

The RSCM (Ruby Source Code Management) gem provides a nice interface to SVN, CVS, ClearCase, StarTeam, etc. and since it’s written in pure Ruby, it runs just fine on the JVM.

Then download this file. Not much to it, 106 lines and 45 of that is the template for creating the rss xml doc.

Command line has a few options, here’s an example:


> jruby -J-server server.rb -p 8080 -m svnlog
or just get help
> jruby server --help

-p, --port=3003                  Which port do you want the server to listen on.
-m, --mount-point=svnrss         http://<your server>/<mount-point>
-h, --help                       Show help (this).

Point your RSS reader @ the following: http://localhost:8080/svnlog?url=http://svn.codehaus.org/jruby/trunk/&num_revs=15 and here’s what you get:

SVN RSS Feed

(Firefox 3 beta)

Nice, think I’ll actually use this.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Digg
  • Reddit
  • DZone