Try in ruby

May 15, 2015

Reading time ~1 minute

Try method

If you get and user is nil the NoMethodError is occurred.

# user is nil
name = # NoMethodError !!!!1

You had better use try method. You can get name value if user is not nil and if user is nil you can get ‘nil’ instead. The NoMethodError is not occurred.

# user is nil
name = user.try(:name) # return nil. not occurred NoMethodError
# user is not nil
name = user.try(:name) # return name value.

You can set default value if user is nil like this.

name = user.try(:name) || "default name"

add ticket number to git commit automatically

Most of ticket tracker like Github, pivotal tracker have function to connect your commit to ticket(story).But every time when you commit ...… Continue reading

I will build frontend and backend separately

Published on September 28, 2016

order of angular controller's initialisation

Published on October 05, 2015