» tagged pages
» logout

sorted by: recent | see : popular
Content Tagged with cool + Ruby

RubyFringe Roundup: The Best Ruby Conference Ever?

rubyfringecrowd.png
(Photo credit: Kieran Huggins)

RubyFringe - described as a "pricey, limited-attendance smoozefest" by Ruby documentation co-ordinator James Britt or as "an avant-garde conference for developers that are excited about emerging technologies outside of the Ruby on Rails monoculture" by the organizers - went ahead last week and appears to have been a significant hit. A small conference with a reasonably high ticket price (though far less than RailsConf Europe!), RubyFringe was set to be a very unique sort of conference with parties, drinks and out-of-hours entertainment laid on, and a limited number of tickets made available to ensure a more intimate gathering. The gamble appears to have paid off.

Praise

I'm not quite sure exactly what went down (I had to pull out of attending) but all references I've seen have been almost over-the-top with excitement and praise:

Soleone says: "Rubyfringe was amazing! So many good talks and great people. Best talk: Giles' presentation on computer generated music. Laughed my ass off!"

Rob Sanheim says: "rubyfringe was a blast, and now i can't sleep."

Lennon Day-Reynolds says: "RubyFringe after-party unsurprisingly turned out to be awesome."

Josh Merchant described it as "an amazing - inspirational - creative- experience."

Heck, there are far too many positive mentions to read on Twitter.

Mark McGranaghan of TechCrunch wrote directly to Ruby Inside:

RubyFringe was a huge win. Unspace set out to raise the bar for software conferences, and I think that they succeeded. I hope that RubyFringe does for web conferences what Rails did for web development; show others that there is a better way, that it does not require corporate sponsorship, and that it can fun, artistic, and productive all at the same time.

Content

There are over 1000 photos from the event on Flickr.

Joey deVilla has put together some handy notes for most of the presentations.

Rowan Hick has put together a list of his RubyFringe highlights.

InfoQ attended the event and, I am told, will be putting up videos of several presentations on their site soon. Until then, the content of the talks is summarized here.

The next RubyFringe?

With such success, it's inevitable another RubyFringe conference will take place within the next year. If you're interested, Pete Forde suggests joining the Google group, and keeping an eye on RubyFringe.com for more info (although it'll be here at Ruby Inside too). It remains to be seen if the success of RubyFringe will encourage "avant garde" conferences elsewhere in the world or for non Ruby communities generally, but Ruby Inside wants to hear about them if so.

Ruby: Inside Ruby

libxml-ruby 0.8.0 Released: Ruby Gets Fast, Reliable XML Processing At Last

Picture 1.png

Ruby's is not known for its deftness with XML. On RubyFlow, I considered calling the community to arms over it, and solicited twenty responses on what the problem is, and what we could do about it. Robert Fischer was lamenting on the state of Ruby's libxml library, and didn't seem to like REXML much either. Tim Bray has also had a few complaints about REXML. It seemed there was a problem to be fixed; a gap in the market, as it were, for a decent XML parser for Ruby. Hpricot, despite really being an HTML parser, would have to get us by in the meantime.

Today, however, libxml-ruby 0.8.0 has been released, and Charlie Savage explains why this is such a big deal. libxml-ruby now runs on Windows (thanks to Charlie), doesn't segfault all the time, and the bindings have all been fixed over the past year (thanks to Dan Janowski). You can get going with it right now with a simple gem install libxml-ruby

libxml-ruby is known for its performance, the latest release doesn't disappoint. For a range of simple tasks, libxml clocks in at ten times quicker than Hpricot like-for-like and between 30 and 60 times faster than REXML. Charles adds:

In addition to performance, the libxml-ruby bindings provide impressive coverage of libxml's functionality. Goodies include:

  • SAX
  • DOM
  • XMLReader (streaming interface)
  • XPath
  • XPointer
  • XML Schema
  • DTDs
  • XSLT (split into the libxslt-ruby bindings)

Charles is planning to write a proper tutorial in the next week, covering some of the key features, but suggests referring to the API documentation in the meantime. The test suite (located in the test directory that comes with libxml-ruby) also looks like a great resource for code examples; very clean and straightforward. If you have any libxml-ruby tutorials or resources of your own, please post them in the comments here.

Congratulations to all of those involved in libxml-ruby's long history and especially to Charlie Savage for giving it the finish push to this mature state. Ruby's XML woes are tempered, for now at least.

Ruby: Inside Ruby

Autumn: Easy, Feature-Rich IRC Bots in Ruby

autumnbot.jpg

Autumn is a framework by Tim Morgan that makes it easy to develop powerful IRC (Internet Relay Chat) bots with Ruby. Version 3, a significant update, was launched just a week ago. The code is available on Github, so it's ready to fork, tweak and work on to your heart's content.

An instance of an "Autumn app" is laid out in a similar way to a Rails app. There are config, doc, script, libs, tmp, and log folders, containing much what you'd expect, as well as a leaves folder (Autumn refers to "bots" as "leaves") that contains any number of folders each containing data, helpers, models, tasks, and "views" for individual bots. A default Autumn app comes with two bots pre-installed called insulter and scorekeeper that you can use to learn from.

Autumn is a pretty significant piece of work and Tim has done an excellent job at documenting it, leaving almost no stone unturned in demonstrating how to create bots / leaves of your own with the framework.

Ruby: Inside Ruby

Join Why The Lucky Stiff (And Others) For an Online “ShoesFest”

shoes-clock.png

You've used Shoes, Why The Lucky Stiff's GUI-app toolkit for Ruby, right? No? You've at least heard of it? (If the answer to this is also no, seriously chastise yourself now.)

Ernest Prabhakar has announced that two online "ShoesFests" will be taking place, involving why the lucky stiff and "friends," with the hope of alluring wannabe hackers (whether on Shoes itself or Shoes-based applications):

The goal of these events is to write and share fun little applications using Shoes, a clever little cross-platform GUI toolkit written in Ruby. This will allow us to test, document, and file bugs on how the various Shoes features work on the different supported platforms (Linux, Windows, Mac), in preparation for our next major release on July 31st, 2008.

No Ruby — or programming — experience is required; we’d love to find out how easy it is for novices to learn Shoes! Of course, if you happen to know the Ruby C API, expert help is always appreciated.

There are two ShoesFests, each taking place for 24 hours, from noon GMT (8am Eastern) on Friday, July 11th, and from noon GMT (8am Eastern) on Friday, July 25th. The venue will be #shoes on the Freenode IRC network (irc.freenode.net).

If spending a day on IRC, asking questions, talking nonsense, helping others, and otherwise hacking away on Shoes and Shoes-based applications with a bunch of exciting people sounds fun to you, make sure to put this Friday in your calendar.

Ruby: Inside Ruby

Cloud computing hype overload

I’ve been working with what I used to call “utility computing” tools for about 6-9 months. However, for about the past 2 months, I’ve been seeing the term “cloud computing” all over the place, and there is so much buzz surrounding it that it’s reaching that magical point best described using Alan Greenspan’s words: “Irrational Exuberance”.

When Alan Greenspan used those words to describe the attitudes of investors toward the markets, what he was basically saying was that there were people who didn’t really know what they were doing, putting more money than they ought, into things they knew relatively little about. Further, he was saying that the decisions people were making with regards to where to put their money were a) bad, or at least b) not based on sound reasoning, or the ‘facts on the ground’.

This, I think, is where we are at with “cloud computing”. The blog post that put me over the edge is this one, for the record. I read Sean’s writings often enough, but this one strikes me as being a little off, a little sensationalistic, not based in reality, and a little misleading.

Maybe he just didn’t put enough qualifiers in there. His post might make more sense if he limited its scope and provided more facts, but I guess it’s just an opinion piece so he decided not to go that route, and that’s his prerogative I guess.

By limiting the scope, I mean he should’ve realized that there are millions of web sites currently scaling quite nicely without the use of cloud computing. In addition, some of the new ones that are having issues are also not using cloud computing, and when they hit bumps in the road, they make it through, and the great thing is that they also share their stories, and those stories indicate that a cloud (or, the current cloud offerings) wouldn’t have helped much (there’s lots of other evidence of that too). What would’ve helped is if they had paid more attention to:

  • monitoring
  • initial infrastructure design
  • their own app code and app design
These aren’t issues that cloud computing takes away. What’s more, cloud computing is something of a moving target, many of the solutions aren’t as mature as you’d want them to be if you’re betting the house on them (EC2 only recently got “elastic IPs” and persistent storage is still not there, AppEngine only supports Python and has some rather severe limitations on functionality of your app), and they introduce a potentially large learning curve both in terms of how the individual services work, as well as how the heck to make your app fit into the cloud solution of your choosing. Think SimpleDB scales? Well, it does, but it’s also not a relational database, and doesn’t guarantee…. much of anything, including data integrity. You can’t interface with it using the drivers, interfaces, and language you’re used to using, either, because it’s not just a mysql wrapper or something - it’s a new beast entirely. Enjoy!
This is not to mention, of course, that some people have absolutely no choice but to scale without the help of the cloud, because corporate policy, common sense, or other forces mean that they can’t have their data passing through non-corporate-owned machines and/or networks. Also, Sean omits any mention of the cost factor, which is often a huge driver in getting startups to use these services, but may not really make the move “worth it” in some cases.
Anyway, in short, all I’m really saying is that it’s disingenuous to say that the future of web computing is “the cloud” because “only the cloud can scale”. That’s just silly. Non-cloud infrastructures can scale fine depending on the balance between the demands of the application and the funds available. The future of web computing will probably involve shared, utility computing architectures, but the future doesn’t depend on cloud computing.
addthis_url = 'http%3A%2F%2Fwww.protocolostomy.com%2F2008%2F07%2F07%2Fcloud-computing-hype-overload%2F'; addthis_title = 'Cloud+computing+hype+overload'; addthis_pub = 'jonesy';

MySQL: Planet MySQL

rbiphonetest: Unit Testing iPhone Apps with Ruby

20080703-mqpqqhdk4e49x3yhhb8t2g9rjg.jpg

Dr Nic Williams has been busy playing with iPhone and Objective C development lately and, unsurprisingly, has found a way to bring Ruby into the mix. He has developed rbiphonetest, a Ruby-based testing framework for iPhone / Objective C applications that uses RubyCocoa to provide the necessary bridge. As well as producing an in-depth 20 minute demonstration screencast, he has also packed some key information into his blog post.

If you're a Rubyist with ambitions of developing native iPhone applications using Objective C (and perhaps even Ruby one day), it's certainly worth a look (as are all of Dr Nic's projects, of course).

Ruby: Inside Ruby

Rails Camp UK in August 2008: Wanna Hack Near London For A Weekend?

railscampuk.png

Note: This item has also been posted on Rails Inside. I don't tend to make it a habit of crossposting items, but as Rails Inside is still very new, I am sure many Ruby Inside readers will want to know about it. Beware, however, you will need to subscribe to Rails Inside to get the skinny on new Rails events in the long term :)

Following on from the outstanding success of the "Rails Camp" events that have taken place in Australia, comes Rails Camp UK, the equivalent for Brits (and brave travellers). The first is from Friday, August 15th to Monday, August 18th and takes place just a 30 minute train ride away from London, in Orpington, Kent (my teenage stomping grounds, as it happens).

The organizers say that they want to get together a "posse of like-minded Ruby hackers" to hack and have fun together in an open environment. The whole weekend costs £45 (and includes food and basic accommodation) with a day pass available for £20. Places are limited. You can sign up on EventWax and a Google group has been put together for attendees to discuss the event.

Post supported by Brightbox: Brightbox is a specialist European Rails hosting company. Each Brightbox server includes an optimised Ruby on Rails stack, SAN storage and access to a managed MySQL database cluster. They also manage dedicated clusters for large scale Rails deployments. Click here to learn more...

Ruby: Inside Ruby

Rails Inside: The Rails-Only Alternative to Ruby Inside

railsinside.gif

It's been years in the making, but it has finally arrived.. Rails Inside, the Rails-only equivalent of Ruby Inside! Featuring an all-new template, Rails Inside presents information in a similar format and style to Ruby Inside but with a focus entirely on the Ruby on Rails scene. If Rails is your main thing, or a significant part of your development life, get over there and subscribe (by RSS or e-mail - the e-mail version actually looks surprisingly nice I've found).

Rails stories will still crop up on Ruby Inside but in slightly lower numbers. With its focus, Rails Inside will feature lots more interesting Rails stories and cover smaller (but still interesting) announcements that Ruby Inside wouldn't traditionally pick up anyway. Further, Rails Inside features small items "From The Rails Blogosphere" in between the regular posts to highlight interesting posts made elsewhere in the Rails blogosphere, making it a one-stop Rails news shop (note that the Rails blogosphere items are on the site only, not the feed, to avoid any annoyance).

It's still early days for Rails Inside, but the site is under active development and I hope to get a few key features rolled out within the next couple of weeks, including a feed of Rails-related events in the sidebar, a Twitter subscription option, and an improved general view of the Rails blogosphere.

This post supported by Rails Kits: Skip the hassle of writing recurring billing code: use the SaaS Rails Kit to quickly add credit card and PayPal payments to your Rails app. Get 10% off by using the discount code "rubyinside" at checkout before August 1st.

Ruby: Inside Ruby

“Beginning Ruby” eBook Only $10 For The Next 24 Hours

beginning-ruby-cover.png

I’ve had word from Apress that they’re doing a one-off 24 hour $10 sale on the e-book version of Beginning Ruby as part of their “daily deal” series. The 24 hours is up - sorry! - but the e-book is still available from Apress at the usual rate of $27.99. It comes as a password protected PDF - no crazy DRM.

Beginning Ruby (Amazon link to the print version) is the ideal book for those new to Ruby, whether fresh to programming or coming from other languages. As well as covering Ruby in a general sense, it also covers the community, a handful of interesting RubyGems, database programming & SQL, object orientation (from the ground up), Rails (though very briefly), and network programming. Not convinced yet? The foreword was drawn by Why The Lucky Stiff, and of the 21 reviews of the book on Amazon.com, 18 give it five stars, and 3 give it four stars (the reviews are well worth reading to see if it’s the sort of book for you).

At $10, even if you’re a bit beyond the level of Beginning Ruby, it might make a good purchase for a co-worker, family member, or anyone else who’s hassling you about Ruby. Feel free to buy a copy and share it around the office. You’re probably not meant to, but I don’t care because if you really wanted to steal, you can just get it off of BitTorrent anyway :)

Finally, while on the Beginning Ruby theme, Amazon has Beginning Ruby available for the Kindle. It’s $23.75, and appears to be the best selling Ruby book on the Kindle so far (which isn’t saying a lot, I appreciate).

Ruby: Inside Ruby

Dave Thomas’s Object Model and Metaprogramming Screencasts

dtvidcap.png

Disclaimer: I have no financial connection to the Pragmatic Programmers and other than through receiving these videos to review get no direct benefit from this review.

It was only a few weeks ago I announced that the Pragmatic Programmers were getting into the screencasting business. The first Ruby related videos were from the Everyday Active Record series by Ryan Bates. The reaction to these across the Ruby blogosphere has been very positive, and true to their word, the Pragmatics have been quick to release some more interesting videos. The latest addition is the Ruby Object Model and Metaprogramming series by Dave Thomas (of Pickaxe fame). Three episodes are available so far, respectively “Objects and Classes,” “Sharing Behavior,” and “Dynamic Code.” They cost $5 each and clock in at around half an hour each.

With the first episode, Dave starts off at a basic level by covering the history of object-oriented development and taking a look at the core elements of what makes up the object-oriented programming style. He moves on to looking at Ruby specific concerns, metaclasses/eigenclasses, anonymous classes, singleton methods, and the like. He manages to keep things at a level that’s immediately accessible to beginners (lots of diagrams are presented to illustrate concepts and relationships between objects and classes) but isn’t afraid to introduce more complex examples straight after. This is a common pattern throughout each of the screencasts, the contents of which are covered here.

I’d recommend these videos to anyone who wants to quickly get up to speed with the concepts involving classes, objects, and metaprogramming. I don’t believe Dave Thomas has done any screencasting before, but he comes across as a natural. His voice is engaging, eager, and authoritative, which makes the videos very easy to follow without drifting off. Certainly, these screencasts are a superb alternative to the explanations of classes, objects and metaprogramming in most Ruby books. If you’re still unsure, Dave gives a quick 3 minute introduction to the series (video).

Elsewhere: Antonio Cangiano has also reviewed these videos. Check out his review for a slightly different perspective.

Post supported by Ruby Hoedown: Come on down to the south for the Ruby Hoedown, the South’s regional Ruby conference! Submit a talk now or sign up for registration at $199. The first 50 people to use the promo code IMINSIDE will get an additional $25 off the price!

Ruby: Inside Ruby

What’s New In Rails 2.1: A Well Produced, Free E-Book

ror21cover.jpg

Ruby on Rails 2.1: What’s New? (PDF, 2MB) is a free e-book written by Carlos Brando (with help from Marcos Tapajos and Daniel Lopes). It was initially written in Brazilian Portuguese (find the original version here), but this version is an English translation by several community members.

As far as community written books goes, it’s pretty good! It comes in at 124 pages, and while 30 of these are just the Rails 2.1 CHANGELOGs (formatted in a nice way, none the less), the rest definitely does a good job of presenting some of the new features of Rails 2.1 (such as named scopes, dirty objects, numerous ActiveRecord changes and time related functions) in a very easy to digest manner.

Ruby: Inside Ruby

PoolParty: One Ruby Gem = Easy EC2 Computing Cloud

poolpartylogo.jpg

Pool Party is a new tool by Ari Lerner (of ProcessorPool fame) that makes it easy to automate the deployment, monitoring (using monit), persistent storage (using S3Fuse), and load balancing (using HAProxy) of EC2 instances. While intended to be application agnostic, there’s naturally a major slant towards Ruby applications in general, with support for Rake tasks a core feature.

Ari’s announcement blog post gives more in-depth details. Development is taking place on Github (where the README is somewhat more readable than with RDoc!) along with discussions at a Google group.

Ari presented PoolParty at RailsConf last week, and his slides are available to view below (or at Scribd):

Ruby: Inside Ruby

21 Ruby Tricks You Should Be Using In Your Own Code

I get to see a lot of Ruby code while writing for Ruby Inside. Most is very good, but sometimes we forget some of Ruby's shortcuts and tricks and instead reinvent the wheel. In this post I present 21 different Ruby tricks, from those that most experienced developers already use every day to those that are more obscure. Before writing this piece, for example, I had no idea about trick number 2! Whatever your level, a refresh may help you the next time you encounter similar scenarios.

Note to beginners: If you are still learning Ruby, check out my Beginning Ruby book (18 5-star reviews so far). It’s only $26.39 on Amazon in print or Kindle format or available from the publisher in PDF format.

1 - Extract regular expression matches quickly

A typical way to extract data from text using a regular expression is to use the match method. There is a shortcut, however, that can take the pain out of the process:

email = "Fred Bloggs <fred@bloggs.com>"
email.match(/<(.*?)>/)[1]            # => “fred@bloggs.com”
email[/<(.*?)>/, 1]                  # => “fred@bloggs.com”
email.match(/(x)/)[1]                # => NoMethodError [:(]
email[/(x)/, 1]                      # => nil
email[/([bcd]).*?([fgh])/, 2]        # => “g”

2 - Shortcut for Array#join

It's reasonably common knowledge that Array#*, when supplied with a number, multiplies the size of the array by duplicate elements, but it's a lot lesser known that when supplied with a string Array#* instead does a join!

%w{this is a test} * ", "                 # => “this, is, a, test”
h = { :name => "Fred“, :age => 77 }
h.map { |i| i * "=" } * "\n"              # => “age=77\nname=Fred”

3 - Format decimal amounts quickly

Formatting floating point numbers into a form used for prices can be done with sprintf or, alternatively, with a formatting interpolation:

money = 9.5
"%.2f" % money                       # => “9.50″

4 - Surround text quickly

The formatting interpolation technique from #3 comes out again, this time to insert a string inside another:

"[%s]" % "same old drag"             # => “[same old drag]“

You can use an array of elements to substitute in too:

x = %w{p hello p}
"<%s>%s</%s>" % x                    # => “<p>hello</p>"

5 - Delete trees of files

Don't resort to using the shell. Ruby comes with a handy file utilities library that can do your bidding:

require 'fileutils'
FileUtils.rm_r 'somedir'

Be careful how you use this one!

6 - Exploding enumerables

* can be used to “explode” enumerables (arrays and hashes). We'll let the examples do the talking:

a = %w{a b}
b = %w{c d}
[a + b]                              # => [["a", "b", "c", "d"]]
[*a + b]                             # => ["a", "b", "c", "d"]
a = { :name => "Fred“, :age => 93 }
[a]                                  # => [{:name => "Fred", :age =>93}]
[*a]                                 # => [[:name, "Fred"], [:age, 93]]
a = %w{a b c d e f g h}
b = [0, 5, 6]
a.values_at(*b).inspect              # => ["a", "f", "g"]

7 - Cut down on local variable definitions

Instead of defining a local variable with some initial content (often just an empty hash or array), you can instead define it “on the go” so you can perform operations on it at the same time:

(z ||= []) << 'test'

8 - Using non-strings or symbols as hash keys

It's very rare you see anyone use non-strings or symbols as hash keys. It's totally possible though, and sometimes handy (and, no, this isn't necessarily a great example!):

does = is = { true => 'Yes', false => 'No' }
does[10 == 50]                       # => “No”
is[10 > 5]                           # => “Yes”

9 - Use 'and' and 'or' to group operations for single liners

This is a trick that more confident Ruby developers use to tighten up their code and remove short multi-line if and unless statements:

queue = []
%w{hello x world}.each do |word|
  queue << word and puts "Added to queue" unless word.length  2
end
puts queue.inspect

# Output:
#   Added to queue
#   Added to queue
#   ["hello", "world"]

10 - Do something only if the code is being implicitly run, not required

This is a very common pattern amongst experienced Ruby developers. If you're writing a Ruby script that could be used either as a library OR directly from the command line, you can use this trick to determine whether you're running the script directly or not:

if __FILE__ == $0
  # Do something.. run tests, call a method, etc. We're direct.
end

11 - Quick mass assignments

Mass assignment is something most Ruby developers learn early on, but it's amazing how little it's used relative to its terseness:

a, b, c, d = 1, 2, 3, 4

It can come in particularly useful for slurping method arguments that have been bundled into an array with *:

def my_method(*args)
  a, b, c, d = args
end

If you want to get really smart (although this is more 'clever' than truly wise):

def initialize(args)
  args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] }
end

12 - Use ranges instead of complex comparisons for numbers

No more if x > 1000 && x nonsense. Instead:

year = 1972
puts  case year
        when 1970..1979: "Seventies"
        when 1980..1989: "Eighties"
        when 1990..1999: "Nineties"
      end

13 - Use enumerations to cut down repetitive code

%w{rubygems daemons eventmachine}.each { |x| require x }

14 - The Ternary Operator

Another trick that's usually learned early on by Ruby developers, but again something I see quite rarely in less experienced developers' code. The ternary operator is not a fix-all, but it can sometimes make things tighter.

puts x == 10 ? "x is ten" : "x is not ten"

# Or.. an assignment based on the results of a ternary operation:
LOG.sev_threshold = ENVIRONMENT == :development ? Logger::DEBUG : Logger::INFO

15 - Nested Ternary Operators

It may be asking for trouble but ternary operators can be nested within each other (after all, they only return objects, like everything else):

qty = 1
qty == 0 ? 'none' : qty == 1 ? 'one' : 'many'
# Just to illustrate, in case of confusion:
(qty == 0 ? 'none' : (qty == 1 ? 'one' : 'many'))

16 - Fight redundancy with Ruby's logical provisions

I commonly see methods using this sort of pattern:

def is_odd(x)
  # Wayyyy too long..
  if x % 2 == 0
    return false
  else
    return true
  end
end

Perhaps we can use a ternary operator to improve things?

def is_odd(x)
  # Don't EVER put false and true in a ternary operator!!
  x % 2 == 0 ? false : true
end

It's shorter, and I see that pattern a lot but really you should go one step further and just rely on the true / false responses Ruby's comparison operators already give!

def is_odd(x)
  # Use the logical results provided to you by Ruby already..
  x % 2 != 0
end

17 - See the whole of an exception's backtrace

def do_division_by_zero; 5 / 0; end
begin
  do_division_by_zero
rescue => exception
  puts exception.backtrace
end

18 - Allow both single items AND arrays to be enumerated against

# [*items] converts a single object into an array with that single object
# of converts an array back into, well, an array again
[*items].each do |item|
  # …
end

19 - Rescue blocks don't need to be tied to a 'begin'

def x
  begin
    # …
  rescue
    # …
  end
end
def x
  # …
rescue
  # …
end

20 - Block comments

I tend to see this in more 'old-school' Ruby code. It's surprisingly under-used though, but looks a lot better than a giant row of pound signs in many cases:

puts "x"
=begin
  this is a block comment
  You can put anything you like here!

  puts “y”
=end
puts "z"

21 - Rescue to the rescue

You can use rescue in its single line form to return a value when other things on the line go awry:

h = { :age => 10 }
h[:name].downcase                         # ERROR
h[:name].downcase rescue "No name"        # => “No name”

If you want to post your own list of Ruby tricks to your blog, send trackback here or leave a comment, and I'll link to all of them in a future post. Alternatively, feel free to post your own Ruby tricks as comments here, or critique or improve on those above.

As an aside, Ruby Inside is exactly two years old today. Thanks for your support! Intriguingly, the first post was another Ruby trick that I forgot to include above, so check that out too.

Ruby: Inside Ruby

Community Engine - Rails Plugin That Adds Social Networking To Your App

Picture 1.png

Prolific Rails developer Bruno Bornsztein (interviewed on Ruby Inside in February 2007) does it again! Not content to settle for releasing 14-plus Rails related projects and Web sites, he has developed Community Engine, an “instant open-source social network plugin” for Rails. Unlike Insoshi and Lovd By Less, which are full social networking Rails applications, Community Engine is a plugin that can add social networking features to existing Rails applications.

Community Engine provides authentication, profile, search, blogging (with tagging, categories and rich-text editing), photo, bookmarking, forum, and other similar functionality. Community Engine has been extracted from the features of two successful social networking sites, Curbly and Uncooped, and has effectively been stress-tested by the general public for the last year.

Ruby: Inside Ruby

Rubinius On Rails: Rubinius Becomes 3rd Ruby Implementation to Run Rails

rubiniusonrails.jpg

Evan Phoenix has announced that the Rubinius project has hit a major milestone: Rubinius can run Rails! This makes it implementation #3 (after MRI and JRuby) to join the Rails club and will help cement its reputation as a strong, key implementation to watch in the future. Chad Fowler goes as far as to assert that in a year’s time, Rubinius will be used in production deployments and quickly become the defacto standard Ruby implementation shortly thereafter.

Eyes are now on Microsoft’s implementation, IronRuby, that may also be joining the Rails club soon.

This post is sponsored by 16bugs — You know how cumbersome most bug trackers are. We know it, too! If you believe bug tracking should be an easy and unobtrusive task, you should try 16bugs right now. Use coupon code “RUBYINSIDE” and get 50% off when you upgrade your account.

Ruby: Inside Ruby

Converting Ruby 1.9 Bytecode to Python

rubytopython.jpg

Never one to let us down on the ingenuity front, Why The Lucky Stiff (author of the Poignant Guide and creator of Shoes) is busy working on a system that can convert Ruby 1.9 bytecode to Python bytecode (and from there into regular Python by way of Python’s decompilation facilities). It’s exactly the sort of thing that could take off with more eyes looking at it, and Why has made it available on GitHub. This technique isn’t likely to unite Python and Ruby in any deep and meaningful way (to the point of a shared interpreter), but the research and experiments involved are worth a try.

Ruby: Inside Ruby

Insoshi: Open-Source Rails-based Social Networking Platform

insoshi.png

Insoshi is a new, open-source social networking platform developed in Ruby on Rails. It’s on GitHub, so you can fork it to your heart’s content, and it can act as a base for developing your own social Web application. Features include activity feeds, profiles, photo sharing, comment walls, blogs, forums, user messaging, and an admin panel.

Insoshi was developed by Michael Hartl, author of RailsSpace, an Addison-Wesley published book about developing a social networking site in Rails. Hartl certainly practices what he preaches! It is important to note, however, that Insoshi is licensed under the Affero General Public License, so making the source code available for your derivative sites is necessary.

Lovd By Less is a similar system previously mentioned here on Ruby Inside that’s also open source and free to use. From what I can make out, both systems are very similar in terms of features (profiles, messaging, blogs, admin system, etc. but Lovd By Less has the edge by being MIT-licensed, making it easier to use in your own commercial applications.

Ruby: Inside Ruby

Migrating to Ruby 1.9

ruby18to19.png

Migrating to Ruby 1.9 was a presentation given by Bruce Williams at Scotland on Rails earlier this month. The slides, available in PDF format, stand on their own extremely well, and will prove a useful resource for anyone not too deeply engrossed in Ruby 1.9 yet. Bruce covers most of the key changes.

As an aside, Bruce was interviewed by Satish Talim of RubyLearning.com recently.

Ruby: Inside Ruby

Ezra Gets Rails® On Rack

awirerack.jpg

Ezra Zygmuntowicz (of Merb and Engine Yard fame) has been spending quite a bit time playing with Rails®, both by cleaning up parts of ActionPack but, more significantly, porting Merb’s Rack mechanics to Rails. He has a personal fork of Rails on Github where he’s doing all the work.

It might not sound particularly impressive work from this description, but Ezra appears to be doing some good work in bringing the Rails dispatch system up to modern standards, and that can only help with Rails’ performance and stability in future. Ezra has also made the mutex locks more granular which provides a “speed boost with standard Mongrel under concurrent load” although more thread-safety testing is, he readily admits, required.

Perhaps more developments on this front will lead to a much needed mod_rack to make deploying Ruby applications on the Web easier without workaround techniques like SwitchPipe or mod_rails. So, let’s give Ezra some applause, and hope he (and maybe others) will keep up this great work :)

Ruby: Inside Ruby

Building a Web App With Merb From Start to Finish

bigwoman.png

Slapp: A simple chat wall Merb tutorial is a perfect example of the sort of tutorial / guide that could encourage a lot of people to try out a new framework (as far as Merb is new, of course). It walks you through the process of developing a “chat wall” type application with Merb from start to finish (right from installing Merb to playing with the running application).

One thing that makes the tutorial stand out is that it puts test spec driven development at the heart of the application. After installing Merb and configuring the database, you’re straight into writing a story with RSpec! This is quite different to most of the Rails introductory articles which skim over testing, and it makes the guide very suitable for those who aren’t familiar with RSpec but who want to learn how to use it while developing a Web application.

Lastly, the “finished” application is available from a Gitorious Git repository for those who want to work backwards or look at the code up front.

Ruby: Inside Ruby

GitHub Officially Launches: Git Hosting A-Go-Go!

github-full.png

It’s been the programming world’s worst kept secret, but the covers are finally off as GitHub officially launched today. No more beta invites needed - hurrah!

GitHub is, officially, a Git repository hosting service (where Git is a source code control system - think decentralized, distributed SVN) built by Chris Wanstrath (Err the Blog), Tom Preston-Werner (creator of Chronic and God), and PJ Hyett. GitHub’s early users are calling it a “social programming network,” a “FaceBook for coders,” and all sorts of wonderful things. This is because Git’s decentralized nature makes it easy to fork, branch and merge code, and so does GitHub, which makes GitHub an ideal platform for collectively working on software, especially open source.

As of Rails 2.1 (coming very soon), GitHub will be the new official home of the Rails source repository, and the Merb, RSpec, Capistrano, Prototype and Scriptaculous projects are also on board, along with hundreds of other Git repositories created by beta users.

GitHub is a commercial offering (though from two open source devotees), but with an incredibly generous free level, meaning that the service is free for most reasonably sized open source projects (that is, the free level covers that sort of open use). There are, of course, a wide range of plans available for the whole gamut of users.

If you haven’t yet given Git a go, don’t fear, as a round up of Git tutorials, tips and tricks (with a Ruby slant, naturally) is coming next here on Ruby Inside. That said, I’ve just noticed InfoQ has already posted something similar, so read that if you’re feeling impatient.

Ruby: Inside Ruby

Interesting Ruby Tidbits That Don’t Need Separate Posts #21

RubyAMP: Amazing Ruby Bundle for TextMate

RubyAMP is a TextMate bundle that goes above and beyond the typical TextMate bundle in usefulness. It adds auto-complete from all open tabs, easy jumping to methods and classes, improved RSpect debugging support, breakpoint support (set and remove from TextMate), Merb / Rails server or console launching, development log tailing, and a lot more. There’s a screencast on the project page itself so you can get a direct look at how it all works within a minute or two.

Bicycle Location Visualization with Ruby and RMagick

bikes-in-paris.jpg

Paris has a shared bicycle scheme for those who want to get around downtown called Velib. Ardent Velib fan Thibaut Barrère decided he wanted a better way to see the availability of bikes, and put together a Ruby app that could scrape the raw data and put together a visualization for him. This is a well written article covering how he did it from start to finish.

Engine Yard Invites Ruby Developers To “Hackfests”

When a press release is so concise and well written (a VERY rare event), it seems a shame not to quote it verbatim:

Engine Yard, provider of the leading Ruby and Rails deployment platform, today announced a series of Hackfests, informal community events open to Ruby developers, where sharing, learning, and hacking rule. The inaugural Hackfest was a resounding success with participation from over 100 top Ruby and Rails developers. Two more Engine Yard Hackfests are planned for the coming months.

The first event was held this past weekend alongside MountainWest RubyConf 2008 in Salt Lake City, Ut., where Engine Yard’s Ezra Zygmuntowicz and Evan Phoenix shared the opening keynote. After the conference, folks generally look to talk tech, shoot the breeze, and hack. They split off into small groups, grab dinner, and eventually end up in various hotel rooms, awake into the wee hours.

The Engine Yard Hackfest aimed to draw these small groups together, and facilitate a mid-sized, casual, expert meeting of the minds. As an alterative to having Rubyists chat in the brief windows between conference sessions, the Hackfest offered an open-all-night comfortable workspace, with free wi-fi, dinner and snacks, and expert community leaders for company.

Rubyists are invited to participate in Engine Yard’s upcoming Hackfests, which will be held alongside GoRuCo in New York (April 26) and RubyFringe in Toronto (July 18-20).

I hear that the similar “Ruby Cave” events at the recent Ruby Fools conferences went down well, so this is a great development for those going to GoRuCo and RubyFringe.

ServiceReg - A RESTful API for RESTful APIs

ServiceReg is a new service by Chris Matthieu (of Wuby fame) that acts as an API to other RESTful APIs. Confused? Perhaps this example URL will give you an idea:

http://servicereg.com/verb/{user:password@}domain/noun{/id?params}

Still don’t get it? Thankfully Chris has put together a screencast to bring us all up to speed. ServiceReg appears to be useful for accessing third party RESTful APIs entirely through a well crafted URL to ServiceReg (without the need to send XML payloads, etc.)

Ruby’s Not Ready! (Or: Why Python Rules and Ruby Sucks)

A Python developer takes Ruby, rips it apart, and explains in 6000+ words why Ruby sucks compared to Python. It’s a ballsy essay, and if it were a lot shorter and not as well written, I’d be calling it Troll Of The Month. As it is, I think he’s missing the point a lot of the time (he tends to think Python’s better because he likes its conventions more than Ruby’s - not a compelling argument), but it’s an interesting read none the less. Anything that keeps our minds open to the fact that Ruby != perfection is worth a look.

Ruby: Inside Ruby

Couldn’t Be At MountainWest RubyConf? Watch The Presentations Now!

mountainwestlogo.png

If you couldn’t get to the popular MountainWest RubyConf two weeks ago, don’t fear. In conjunction with Confreaks, videos of all of the presentations are available to watch online. 14 videos are available, including the following:

Strengthening the Ruby Ecosystem Part I: Rubinius by Evan Phoenix - Evan gives a general overview of Rubinius, how the project has worked out so far, and what the goal is with its development.

Strengthening the Ruby Ecosystem Part II: Merb by Ezra Zygmuntowicz - A similarly general overview of Merb, a Ruby Web applications framework. A great executive overview of the Merb project generally.

Code Generation: The Safety Scissors of Metaprogramming by Giles Bowkett - Giles looks at the beauties (and dangers!) of meta programming and other voodoo with Ruby. This is a particularly interesting talk, and an ideal one to watch if you’re short of time.

Faster, Better ORM with DataMapper by Yehuda Katz - An overview of the DataMapper ORM, a compelling alternative to ActiveRecord.

Deep Ruby by Jeremy McAnally - A look at Ruby’s object model and other “deep” Ruby issues. This is a pretty interesting talk too, for those who like to look at the nitty gritty.

BDD with Shoulda by Tammer Saleh - Shoulda is a great, small, simple testing plugin for Rails applications with a BDD flavor.

Lightning Talks by Various - The lightning talks include Mike Moore doing a “Binary Lottery” program with _why’s Shoes, Chris Shea talking about “Guessmethod“, Ed Moss talking about Active Scaffold, and more.

It seems MountainWest had a really high quality level of talks, so give it a thought when choosing which Ruby events to attend next year.

(On another level, I’m kinda surprised by how many Rubyists seem to have ended up working in groups - whether ThoughtBot, ENTP, or Engine Yard.)

<