Project

General

Profile

Bug #1387

first(0) and last(0) behavior

Added by loqi (Loqi Tamaroon) about 10 years ago. Updated about 8 years ago.

Status:
Third Party's Issue
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
1.8.6

Description

=begin
I'm not sure if there was an explicit decision to have Array#first(0) and last(0) return the entire receiver, but it's messing me up slightly.

"abc".first(3) => "abc"
"abc".first(2) => "ab"
"abc".first(1) => "a"
"abc".first(0) => "abc"

There's similar behavior with last(0).

In my opinion, first(0) and last(0) should return a zero-length collection.

Is there a rationale for their current behavior, or is it a mistake?
=end

Associated revisions

Revision 5f671527
Added by hsbt (Hiroshi SHIBATA) over 3 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 52666
Added by hsbt (Hiroshi SHIBATA) over 3 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

Revision 52666
Added by hsbt (Hiroshi SHIBATA) over 3 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

Revision 52666
Added by hsbt (Hiroshi SHIBATA) over 3 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

Revision 52666
Added by hsbt (Hiroshi SHIBATA) over 3 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

Revision 52666
Added by hsbt (Hiroshi SHIBATA) over 3 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

History

#1

Updated by daz (Dave B) about 10 years ago

=begin
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 <main>': undefined methodfirst' 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.

daz

=end

#2

Updated by matz (Yukihiro Matsumoto) about 10 years ago

  • Status changed from Open to Third Party's Issue

=begin

=end

Also available in: Atom PDF