Posts

Showing posts from May, 2015

Tip : "Clear" in Rails Console

I don’t know about you, It doesnt feel nice when i am working at the bottom of my terminal window, or there’s a huge unnecessary output above where I’m working.

Unfortunately, the typical terminal clear command doesn’t work in the console:

>> clear NameError: undefined local variable or method 'clear' for # from (irb):1 So here is the trick use ctrl + l (with a lowercase L) and for Mac users, Command + k

Tip: Rescue blocks in Ruby

Everybody must have heard and used the exception handling in Ruby. But here is one trick that might be useful. "Rescue blocks don't need to be tied to a 'begin' "

def x begin # ... rescue # ... end end
def x # ... rescue # ... end
You can also use rescue in its single line form to return a value when other things produces error.

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