Skip to content

Commit

Permalink
AS guide: removes docs for String#start_with? and String#end_with?, n…
Browse files Browse the repository at this point in the history
…o longer in AS
  • Loading branch information
fxn committed Nov 9, 2009
1 parent 7982956 commit 9754deb
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions railties/guides/source/active_support_core_extensions.textile
Original file line number Diff line number Diff line change
Expand Up @@ -635,31 +635,15 @@ In Ruby 1.9 the <tt>%</tt> string operator supports key-based interpolation, bot

Active Support adds that functionality to <tt>%</tt> in previous versions of Ruby.

h4. +start_with?+ and +end_width?+
h4. +starts_with?+ and +ends_width?+

Ruby 1.8.7 and up define the predicates +String#start_with?+ and +String#end_with?+:

<ruby>
"foo".start_with?("f") # => true
"foo".start_with?("g") # => false
"foo".start_with?("") # => true

"foo".end_with?("o") # => true
"foo".end_with?("p") # => false
"foo".end_with?("") # => true
</ruby>

If strings do not respond to those methods Active Support emulates them, and also defines their 3rd person aliases:
Active Support defines 3rd person aliases of +String#start_with?+ and +String#end_with?+:

<ruby>
"foo".starts_with?("f") # => true
"foo".ends_with?("o") # => true
</ruby>

in case you feel more comfortable spelling them that way.

WARNING. Active Support invokes +to_s+ on the argument, but Ruby does not. Since Active Support defines these methods only if strings do not respond to them, this corner of their behaviour depends on the interpreter that runs a given Rails application. You change the interpreter, and +start_with?(1)+ may change its return value. In consequence, it's more portable not to rely on that and pass always strings.

h4. Access

h5. +at(position)+
Expand Down

0 comments on commit 9754deb

Please sign in to comment.