Ruby: get 1.month into a string -


ruby has amazing time object handling. eg. 1.month + 1.day

i'd convert 1.month string "1 month", , in rails model.

how can that?

thanks

using inspect gives string when i've tried it.

1.month.inspect #=> "1 month" 2.months.inspect #=> "2 months" 2.month.inspect #=> "2 months" 

update point of interest, didn't find answer in documentation. (maybe it's available somewhere, haven't seen it.) first step try 2 candidates when trying string value (to_s , inspect) , found way. however, continued try find way isn't based on using inspect looking @ methods available using 1.month.methods.sort , looking @ various to_* methods. last can handy thing try when attempting figure out particular ruby object provide.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -