311 To Learn More Programming Ruby and The Ruby Programming Language Flanagan

311 to learn more programming ruby and the ruby

This preview shows page 127 - 130 out of 517 pages.

the most productive one for each new job. 3.11 To Learn More Programming Ruby and The Ruby Programming Language ( Flanagan and Matsumoto 2008 ), co-
Image of page 127
authored by Ruby inventor Yukihiro “Matz” Matsumoto, are definitive references for Ruby. The online documentation for Ruby gives details on the language, its classes, and its standard libraries. A few of the most useful classes include IO (file and network I/O, including CSV files), Set (collection operations such as set difference, set intersection, and so on), and Time (the standard class for representing times, which we recommend over Date even if you’re representing only dates without times). These are reference materials, not a tutorial. Learning Ruby Fitzgerald 2007 takes a more tutorial-style approach to learning the language. The no-cost, Creative Commons-licensed, and quirky Why’s (Poignant) Guide to Ruby is an interesting alternative, though some material may be outdated since that document was written for Ruby 1.8. The Ruby Way, Second Edition is an encyclopedic reference to both Ruby itself and how to use it idiomatically to solve many practical programming problems. Many newcomers to Ruby have trouble with yield , which has no equivalent in Java, C or C++ (although recent versions of Python and JavaScript do have similar mechanisms). The coroutines article on Wikipedia gives good examples of the general coroutine mechanism that yield supports. Ruby Best Practices Brown 2009 focuses on how to make the best of Ruby’s “power tools” like blocks, modules/duck-typing, metaprogramming, etc. If you want to write Ruby like a Rubyist instead of writing Java code in Ruby, this is a great read. G. T. Brown. Ruby Best Practices . O’Reilly Media, 2009. ISBN 0596523009. M. J. Fitzgerald. Learning Ruby . O’Reilly Media, 2007. ISBN 0596529864. D. Flanagan and Y. Matsumoto. The Ruby Programming Language . O’Reilly Media, 2008. ISBN 0596516177. 3.12 Suggested Projects OO and Classes Project 3.1. How many class ancestors does the object 5 have? (Hint: use method chaining to follow the superclass chain all the way up to BasicObject ) Project 3.2. Given that superclass returns nil when called on BasicObject but a non- nil value otherwise, write a Ruby method that, if passed any object, will print the object’s class and its ancestor classes all the way up to BasicObject . Project 3.3. Ben Bitdiddle asks: “If i is an integer and f is a floating point number in Ruby, and I write i+f , does i get converted to a float or does f get converted to an integer to do the addition?” Explain why Ben’s question is ill-formed when applied to Ruby. Project 3.4. Newly enlightened by the answer to Project 3.3 , Ben now observes that writing i+=f is legal Ruby. His question is: “Is += a separate operator in Ruby, or is it purely syntactic sugar for i=i+f ?” Devise and carry out an experiment to determine the answer. Metaprogramming Project 3.5. Building on the example in Section 3.5 , take advantage of Time ’s duck typing to define a
Image of page 128
method at_beginning_of_year that lets you write: 1 Time.now.at_beginning_of_year + 1.day 2 # => 2011-01-02 00:00:00 -0800 Hint 1: The Time documentation will tell you that the local
Image of page 129
Image of page 130

You've reached the end of your free preview.

Want to read all 517 pages?

  • Spring '19
  • Dr.Marcos

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors