Skip to main content

Diigo Home

Ruby Programming/Introduction to objects - Wikibooks, collection of open-conte... - The Diigo Meta page

en.wikibooks.org/...Introduction_to_objects - Cached - Annotated View

Benx Shen's personal annotations on this page

benxshen
Benxshen bookmarked on 2009-10-24
  • In Ruby, methods that end with an exclamation mark (also called a "bang") modify the object. For example, the method upcase! changes the letters of a String to uppercase.


    >> comedian.upcase!
    => "STEPHEN COLBERT"

    Since both of the variables comedian and favorite_comedian point to the same String object, we can see the new, uppercase text using either variable.


    >> comedian
    => "STEPHEN COLBERT"
    >> favorite_comedian
    => "STEPHEN COLBERT"

    Ruby - Introduction to objects - Two variables, modified object.png

This link has been bookmarked by 1 people . It was first bookmarked on 24 Oct 2009, by Benx Shen.

  • 24 Oct 09
    • In Ruby, methods that end with an exclamation mark (also called a "bang") modify the object. For example, the method upcase! changes the letters of a String to uppercase.


      >> comedian.upcase!
      => "STEPHEN COLBERT"

      Since both of the variables comedian and favorite_comedian point to the same String object, we can see the new, uppercase text using either variable.


      >> comedian
      => "STEPHEN COLBERT"
      >> favorite_comedian
      => "STEPHEN COLBERT"

      Ruby - Introduction to objects - Two variables, modified object.png