Answer the question
In order to leave comments, you need to log in
How can a hash value trim all spaces?
I have this hash hash["price"] = 5 000.
How can I apply .lstrip to the hash value?
I need it to cut the space between five and zeros, because when I load it via csv, it loads only the numbers before the space in the price:integer field.
Answer the question
In order to leave comments, you need to log in
hash["price"] = "5 000".sub!(" ", "")
=> "5000"
sub!
will change the value in the hash. If you just need to pass a string with the amount, but not change the hash - just "sub".
hash.values.each(&:lstrip!)
But, since you need to remove all spaces in a string with a number, thenhash.values.each{ |v| v.delete!(' ') }
There is a to_money method - either when saving to a hash, do hash["price"]=price.to_money, or when outputting to csv, return hash["price"].to_money
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question