Forum: Ruby Re: string slice elegant way

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Pena, Botp (Guest)
on 2006-03-04 01:41
(Received via mailing list)
Mage [mailto:mage@mage.hu]

#a = 'hello there'
#and I need 'llo there'
#
#a[2,a.size] works, but I find it ugly because the given length
#is larger
#than the real length of the result.
#a[2,a.size - 2] is okay, but it is not DRY.
#
#Is there any elegant way, like a[2:] in Python?

is a[2..-1] good enough?
36958dd94ca666a38483df282a5214d5?d=identicon&s=25 Peter Ertl (Guest)
on 2006-03-04 06:43
(Received via mailing list)
this is the closest I could think of:

a = "hello there"
a[-9,9]
> llo there
This topic is locked and can not be replied to.