Skip to content

Commit

Permalink
String#chars is not an alias to String#each_char
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Oct 23, 2013
1 parent b1b16dd commit 452545a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions corelib/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,7 @@ def center(width, padstr = ' ')
end

def chars
return enum_for :chars unless block_given?

%x{
for (var i = 0, length = self.length; i < length; i++) {
#{yield `self.charAt(i)`};
}
}

self
each_char.to_a
end

def chomp(separator = $/)
Expand Down Expand Up @@ -235,7 +227,17 @@ def downcase
`self.toLowerCase()`
end

alias each_char chars
def each_char(&block)
return enum_for :each_char unless block_given?

%x{
for (var i = 0, length = self.length; i < length; i++) {
#{yield `self.charAt(i)`};
}
}

self
end

def each_line(separator = $/)
return split(separator) unless block_given?
Expand Down

0 comments on commit 452545a

Please sign in to comment.