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
Post a Comment