Skip to content
Permalink
Browse files

Merge pull request #702 from tobarja/Symbol#slice

Symbol#slice is equivalent to sym.to_s.slice, per ruby-doc.
  • Loading branch information
alex committed May 15, 2013
2 parents e6911a3 + efb2871 commit 2387d2792275ac47a92ed6ae6d5ba893cec9180e
@@ -23,4 +23,5 @@ Authors
* David Schneider
* Robin Schreiber
* Jan Stępień
* Andrew Thompson
* Jeremy Thurgood
@@ -22,6 +22,11 @@ def capitalize
self.to_s.capitalize.to_sym
end

def [](*args)
self.to_s[*args]
end
alias slice []

def swapcase
self.to_s.swapcase.to_sym
end
@@ -1,36 +1,3 @@
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 a 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
fails:Symbol#[] with a Range slice that is out of bounds returns nil if the first range value begins past the end
fails:Symbol#[] with a Range slice that is out of bounds returns a blank string if the first range value is within bounds and the last range value is not
fails:Symbol#[] with a Range slice that is out of bounds returns nil if the first range value starts from the end and is within bounds and the last value starts from the end and is greater than the length
fails:Symbol#[] with a Range slice that is out of bounds returns nil if the first range value starts from the end and is out of bounds and the last value starts from the end and is less than the length
fails:Symbol#[] with a Range slice with Float values converts the first value to an Integer
fails:Symbol#[] with a Range slice with Float values converts the last value to an Integer
fails:Symbol#[] with a Range subclass slice returns a slice
fails:Symbol#[] with a Regex slice without a capture index returns a string of the match
fails:Symbol#[] with a Regex slice without a capture index returns nil if the expression does not match
fails:Symbol#[] with a Regex slice without a capture index sets $~ to the MatchData if there is a match
@@ -39,12 +6,8 @@ fails:Symbol#[] with a Regex slice with a capture index returns a string of the
fails:Symbol#[] with a Regex slice with a capture index returns a string for the matched capture at the given index
fails:Symbol#[] with a Regex slice with a capture index returns nil if there is no capture for the index
fails:Symbol#[] with a Regex slice with a capture index converts the index to an Integer
fails:Symbol#[] with a Regex slice with a capture index raises a TypeError if the index is nil
fails:Symbol#[] with a Regex slice with a capture index sets $~ to the MatchData if there is a match
fails:Symbol#[] with a Regex slice with a capture index does not set $~ to the MatchData if there is not a match
fails:Symbol#[] with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Hash
fails:Symbol#[] with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Array
fails:Symbol#[] with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Object
fails:Symbol#[] with a String slice does not set $~
fails:Symbol#[] with a String slice returns a string if there is match
fails:Symbol#[] with a String slice returns nil if there is not a match
@@ -1,36 +1,9 @@
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 a 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
fails:Symbol#slice with a Range slice that is out of bounds returns nil if the first range value begins past the end
fails:Symbol#slice with a Range slice that is out of bounds returns a blank string if the first range value is within bounds and the last range value is not
fails:Symbol#slice with a Range slice that is out of bounds returns nil if the first range value starts from the end and is within bounds and the last value starts from the end and is greater than the length
fails:Symbol#slice with a Range slice that is out of bounds returns nil if the first range value starts from the end and is out of bounds and the last value starts from the end and is less than the length
fails:Symbol#slice with a Range slice with Float values converts the first value to an Integer
fails:Symbol#slice with a Range slice with Float values converts the last value to an Integer
fails:Symbol#slice with a Range subclass slice returns a slice
fails:Symbol#slice with a Regex slice without a capture index returns a string of the match
fails:Symbol#slice with a Regex slice without a capture index returns nil if the expression does not match
fails:Symbol#slice with a Regex slice without a capture index sets $~ to the MatchData if there is a match
@@ -39,12 +12,8 @@ fails:Symbol#slice with a Regex slice with a capture index returns a string of t
fails:Symbol#slice with a Regex slice with a capture index returns a string for the matched capture at the given index
fails:Symbol#slice with a Regex slice with a capture index returns nil if there is no capture for the index
fails:Symbol#slice with a Regex slice with a capture index converts the index to an Integer
fails:Symbol#slice with a Regex slice with a capture index raises a TypeError if the index is nil
fails:Symbol#slice with a Regex slice with a capture index sets $~ to the MatchData if there is a match
fails:Symbol#slice with a Regex slice with a capture index does not set $~ to the MatchData if there is not a match
fails:Symbol#slice with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Hash
fails:Symbol#slice with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Array
fails:Symbol#slice with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Object
fails:Symbol#slice with a String slice does not set $~
fails:Symbol#slice with a String slice returns a string if there is match
fails:Symbol#slice with a String slice returns nil if there is not a match
@@ -501,6 +501,7 @@ def method_hash(self, space):
return space.newint(self.strategy.hash(self.str_storage))

@classdef.method("[]")
@classdef.method("slice")
def method_subscript(self, space, w_idx, w_count=None):
start, end, as_range, nil = space.subscript_access(self.length(), w_idx, w_count=w_count)
if nil:

0 comments on commit 2387d27

Please sign in to comment.
You can’t perform that action at this time.