From: Jeremy Kemper Date: 2009-04-18T01:25:08+09:00 Subject: [ruby-core:23238] Re: [Bug #1387] first(0) and last(0) behavior On Fri, Apr 17, 2009 at 11:03 AM, Dave B wrote: > Issue #1387 has been updated by Dave B. > > > Those methods (for String) don't exist in Matz Ruby: > > puts 'ruby %s (%s) [%s]' % [RUBY_VERSION, RUBY_RELEASE_DATE, RUBY_PLATFORM] > > p "abc".first(1) > > #ruby 1.8.6 (2008-08-11) [i386-mswin32] > #tmp:3: undefined method `first' for "abc":String (NoMethodError) > > # ... neither in 1.9.1 ... > > #ruby 1.9.1 (2009-01-30) [i386-mswin32_90] > # tmp:3:in `
': undefined method `first' for "abc":String (NoMethodError) > > A quick search finds they are added by Rails but maybe you have > some other library which adds the methods. > http://errtheblog.com/posts/42-rails-rubyisms-advent > > Either way, if you can't track them down, try asking on either > the ruby-talk or Rails lists. In Rails, String#first is self[0..(n-1)], so "abc".first(0) == "abc"[0..-1] == "abc" Changing this to self[0...n] would satisfy your expectation: "abc"[0...0] == "" Please submit a patch to Rails :) jeremy