Skip to Content
Metaprogramming Ruby 2
book

Metaprogramming Ruby 2

by Paolo Perrotta
August 2014
Intermediate to advanced
250 pages
6h 20m
English
Pragmatic Bookshelf
Content preview from Metaprogramming Ruby 2

Chapter 5Thursday: Class Definitions

As you know, writing object-oriented programs means spending a good chunk of your time defining classes. In Java and C#, defining a class is like making a deal between you and the compiler. You say, “Here’s how my objects are supposed to behave,” and the compiler replies, “Okay, they will.” Nothing really happens until you create an object of that class and then call that object’s methods.

In Ruby, class definitions are different. When you use the class keyword, you aren’t just dictating how objects will behave in the future. On the contrary, you’re actually running code.

If you buy into this notion—that a Ruby class definition is actually regular code that runs—you’ll be able to cast some powerful spells. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Ruby Programming Language

The Ruby Programming Language

David Flanagan, Yukihiro Matsumoto
Head First Ruby

Head First Ruby

Jay McGavren
Eloquent Ruby

Eloquent Ruby

Russ Olsen

Publisher Resources

ISBN: 9781941222751Errata Page