Tag ‘Ruby’

Code blocks with optional arguments in Ruby 1.8.x

Ruby 1.9 has some cool new features. One of them is the ability to define default values for the arguments passed to code blocks, like in the following example:

pow = proc { |a, b = 2| a**b }
 
pow.call 3, 3
# 27
 
pow.call 3
# 9

This is very useful, for instance, when we dynamically create new methods using metaprogramming and want some of the arguments for these methods to be optional.

class MyMath
  class < < self
    define_method

Continue reading

Using cucumber and webrat for remote web testing

Cucumber and webrat serve as a powerful combination of tools for testing your web applications, but in its most common mode webrat can only test your application locally. Is it possible, you may ask, to use webrat to test a remote web site? The answer is yes, with a little tweaking. Webrat has a configuration option that tells it to use mechanize (a screen-scraping tool for ruby) instead of the built-in rails view testing system.

Continue reading

best railsconf title

Brad Midgley

The best title had to be When to Tell Your Kids About Client Caching. Parents might identify more with this. Interesting stuff in any case.

Continue reading

Ruby performance work

Brad Midgley

Railsconf had several performance-related talks. This one went over a lot of interesting territory.

  • Who knew the Date class performed so badly?? Use equivalent ops in Time or get date::performance
  • Use String::<< instead of String::+=
  • Tune your custom sql with virtual attributes

It’s surprising that things we might not think are performance issues are problematic in ruby. One reason to optimize after you gather metrics that identify problem areas.

rowing

(Image courtesy of rowingbike.com)

Continue reading

RubyMine

Brad Midgley

During his talk at railsconf, Gregg Pollack showed off Jetbrains Rubymine, an awesome IDE for ruby & rails. I wouldn’t be surprised to find out Jetbrains had a spike in their downloads coinciding with the talk. It is a nice IDE. I was happy to see it includes git support out of the box (I only had to set the path to the git executable).  I like the web preview for rails applications. On the downside,

Continue reading