Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: dbc430f07bff
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: eb9517ef5f39
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Mar 3, 2015

  1. Copy the full SHA
    c9ef2a2 View commit details
  2. Merge pull request #2643 from bjfish/truffle_symbol_slice

    [Truffle] Adding Symbol#[] in ruby.
    chrisseaton committed Mar 3, 2015
    Copy the full SHA
    eb9517e View commit details
19 changes: 0 additions & 19 deletions spec/truffle/tags/core/symbol/element_reference_tags.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
fails:Symbol#[] with an Integer index returns the character code of the element at the index
fails:Symbol#[] with an Integer index returns nil if the index starts from the end and is greater than the length
fails:Symbol#[] with an Integer index returns nil if the index is greater than the length
fails:Symbol#[] with an Integer index and length and a positive index and length returns a slice
fails:Symbol#[] with an Integer index and length and a positive index and length returns a blank slice if the length is 0
fails:Symbol#[] with an Integer index and length and a positive index and length returns a slice of all remaining characters if the given length is greater than the actual length
fails:Symbol#[] with an Integer index and length and a positive index and length returns nil if the index is greater than the length
fails:Symbol#[] with an Integer index and length and a positive index and negative length returns nil
fails:Symbol#[] with an Integer index and length and a negative index and positive length returns a slice starting from the end upto the length
fails:Symbol#[] with an Integer index and length and a negative index and positive length returns a blank slice if the length is 0
fails:Symbol#[] with an Integer index and length and a negative index and positive length returns a slice of all remaining characters if the given length is larger than the actual length
fails:Symbol#[] with an Integer index and length and a negative index and positive length returns nil if the index is past the start
fails:Symbol#[] with an Integer index and length and a negative index and negative length returns nil
fails:Symbol#[] with an Integer index and length and a Float length converts the length to an Integer
fails:Symbol#[] with an Integer index and length and a nil length raises a TypeError
fails:Symbol#[] with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Array
fails:Symbol#[] with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Hash
fails:Symbol#[] with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Object
fails:Symbol#[] with a Float index converts the index to an Integer
fails:Symbol#[] with a nil index raises a TypeError
fails:Symbol#[] with an index that cannot be converted into an Integer raises a TypeError when given an Array
fails:Symbol#[] with an index that cannot be converted into an Integer raises a TypeError when given an Hash
fails:Symbol#[] with an index that cannot be converted into an Integer raises a TypeError when given an Object
fails:Symbol#[] with a Range slice that is within bounds returns a slice if both range values begin at the start and are within bounds
fails:Symbol#[] with a Range slice that is within bounds returns a slice if the first range value begins at the start and the last begins at the end
fails:Symbol#[] with a Range slice that is within bounds returns a slice if the first range value begins at the end and the last begins at the end
19 changes: 0 additions & 19 deletions spec/truffle/tags/core/symbol/slice_tags.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
fails:Symbol#slice with an Integer index returns the character code of the element at the index
fails:Symbol#slice with an Integer index returns nil if the index starts from the end and is greater than the length
fails:Symbol#slice with an Integer index returns nil if the index is greater than the length
fails:Symbol#slice with an Integer index and length and a positive index and length returns a slice
fails:Symbol#slice with an Integer index and length and a positive index and length returns a blank slice if the length is 0
fails:Symbol#slice with an Integer index and length and a positive index and length returns a slice of all remaining characters if the given length is greater than the actual length
fails:Symbol#slice with an Integer index and length and a positive index and length returns nil if the index is greater than the length
fails:Symbol#slice with an Integer index and length and a positive index and negative length returns nil
fails:Symbol#slice with an Integer index and length and a negative index and positive length returns a slice starting from the end upto the length
fails:Symbol#slice with an Integer index and length and a negative index and positive length returns a blank slice if the length is 0
fails:Symbol#slice with an Integer index and length and a negative index and positive length returns a slice of all remaining characters if the given length is larger than the actual length
fails:Symbol#slice with an Integer index and length and a negative index and positive length returns nil if the index is past the start
fails:Symbol#slice with an Integer index and length and a negative index and negative length returns nil
fails:Symbol#slice with an Integer index and length and a Float length converts the length to an Integer
fails:Symbol#slice with an Integer index and length and a nil length raises a TypeError
fails:Symbol#slice with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Array
fails:Symbol#slice with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Hash
fails:Symbol#slice with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Object
fails:Symbol#slice with a Float index converts the index to an Integer
fails:Symbol#slice with a nil index raises a TypeError
fails:Symbol#slice with an index that cannot be converted into an Integer raises a TypeError when given an Array
fails:Symbol#slice with an index that cannot be converted into an Integer raises a TypeError when given an Hash
fails:Symbol#slice with an index that cannot be converted into an Integer raises a TypeError when given an Object
fails:Symbol#slice with a Range slice that is within bounds returns a slice if both range values begin at the start and are within bounds
fails:Symbol#slice with a Range slice that is within bounds returns a slice if the first range value begins at the start and the last begins at the end
fails:Symbol#slice with a Range slice that is within bounds returns a slice if the first range value begins at the end and the last begins at the end
22 changes: 22 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/symbol.rb
Original file line number Diff line number Diff line change
@@ -32,4 +32,26 @@ def succ

alias_method :next, :succ

def [](index, other = undefined)
if index.kind_of?(Regexp)
unless undefined.equal?(other)
match, str = to_s.send(:subpattern, index, other)
Regexp.last_match = match
return str
end

str = to_s
match_data = index.search_region(str, 0, str.num_bytes, true)
Regexp.last_match = match_data
if match_data
result = match_data.to_s
return result
end
else
to_s[index, other]
end
end

alias_method :slice, :[]

end