ROR + Ruby Function To Access Last Value Of An Variable
In Ruby 1.8.6
, I want to the last value of any string.
For example : notice_5
here, I want "5"
in one of the variable. So please suggest any function through which 开发者_StackOverflow社区I can get 5 in one of the variable.
Thanks
Use index -1
var = "somevar_5"
var[0]
=> "s"
var[-1] # get character code
=> 53
var[-1].chr #get character
=> "5"
Got the Solution
>> a = 'hello_7'
=> "hello_7"
>> a.last
=> "7"
精彩评论