1 .
h = { :age => 10 } h[:name].downcase # ERROR h[:name].downcase rescue "No name" # => "No name"
2.
Before
def x begin # ... rescue # ... end end
After
def x # ... rescue # ... end
3.
%w{rubygems daemons eventmachine}.each { |x| require x }
4.
a, b, c, d = 1, 2, 3, 4
def my_method(*args) a, b, c, d = args end
def initialize(args) args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] } end
5.
"[%s]" % "same old drag" # => "[same old drag]"
x = %w{p hello p} "<%s>%s</%s>" % x # => "<p>hello</p>"