D
drKreso
I am interesed in Ruby idiomatic way to get array of all possible
slices of particular string. For example
if I have string "hello" i would like to get
["hello", "ello", "llo", "lo", "o", "default"]
and a "default" on the end... This is what I came up with but it
doesn't feel right.
# all possible keys
# ex. for 211 keys are [211,11,1,"default"]
def keys
result = []
amount_as_string = @amount.to_s
while(amount_as_string != "")
result << amount_as_string.to_i
amount_as_string.slice!(0)
end
result << "default"
end
Help would be appreciated.
Best Regards
Kresimir Bojcic
www.kresimirbojcic.com
slices of particular string. For example
if I have string "hello" i would like to get
["hello", "ello", "llo", "lo", "o", "default"]
and a "default" on the end... This is what I came up with but it
doesn't feel right.
# all possible keys
# ex. for 211 keys are [211,11,1,"default"]
def keys
result = []
amount_as_string = @amount.to_s
while(amount_as_string != "")
result << amount_as_string.to_i
amount_as_string.slice!(0)
end
result << "default"
end
Help would be appreciated.
Best Regards
Kresimir Bojcic
www.kresimirbojcic.com