string - Can I use strip! and chomp! in one line in Ruby -


i see strip! , chomp! (and other similar methods) return nil when string not altered. apparently forbids combining these methods in 1 line:

s = 'a' # => "a"    s.strip!.chomp!(',')   # => nomethoderror: undefined method `chomp!' nil:nilclass 

so seem forced write 1 per line:

s.strip! # => nil   s.chomp!(',') # => nil   

is way or missing something?

you use non-mutating versions of methods:

s = s.strip.chomp(',') 

you use semicolon (but poor taste):

s.strip!; s.chomp!(',') 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -