Robert is a voracious reader, Ruby aficionado, and other big words.
selfis always the current object.
- Rather than declaring instance variables in constructors as in static languages, it’s sometimes better to take advantage of lazy initialization methods.
#instance_evalruns a block or string in the context of an instance, including instances of
#class_evalto define methods for all instances of a class.
- There is no difference between compile-time and run-time code in Ruby.
- In Ruby, a constant is any word that begins with a capital letter.
- Constants are mostly used for class and module names, never as enums like in other languages.
- The scope-resolution operator
::is used to specify constants
::at the front of a constant to specify a root level constant.
- Private methods are methods that cannot have an explicit receiver, including
- Objects receive messages to call methods.
.operator is shorthand for
#sendto send a message to an object
#method_missingcan intervene when an object does not know how to respond to a message.
- It’s important to define
- An eigenclass or singleton class is a unique class an object is linked to.
class < <syntax can be used to open an object’s eigenclass, including a class object.
- Class methods cannot be private, but eigenclass methods defined on classes can.
- Methods like
attr_accessorcan be defined as class-level methods of classes or instance-level methods of
Once internalized, Ruby is a fairly straightforward language. Until that happens, however, many potential converts are turned off by some of its more unusual aspects. This series hopes to clear up some of the confusion that newcomers face when learning Ruby. There will be an attempt to adhere to the RDoc notation for describing methods: […]
If you’ve been coding in Ruby for any length of time, you’ve probably at least heard of Shoes. Shoes is a DSL / GUI toolkit originally developed by the famed _why The Lucky Stiff. It’s also the basis for the Hackety Hack program that helps users learn Ruby and GUI programming. You can find the […]
Parsing is…complicated. And yet, we wouldn’t have many facets of the modern world without it. Our ability to get behavior out of a computer is limited by the expressiveness of our programming languages. And the programming languages available to us are limited by our parsing techniques. The construction of a programming language consists of at […]
I like to think of forking as the underdog of the concurrency world. In fact, at this point, many programmers have probably never even heard of it. The term “multithreaded” has almost become synonymous with “concurrent” or “parallel.” The fork() system call creates a “copy” of the current process. For our purposes in Ruby, it […]
This entry is part 4 of 4 in the series A Guide to Ruby Collections This is the last article in the Guide to Ruby Collections series. I want to finish up by providing some miscellaneous tips that you will hopefully find helpful during your Ruby adventures. More Detailed Array Creation In the introduction to […]
This entry is part 3 of 4 in the series A Guide to Ruby Collections In this article, I’m going to cover the Enumerable module and the Enumerator class. In order to get maximum use out of Ruby’s collections, you will need to understand how they work and what they give you. In particular, Enumerable […]
This entry is part 2 of 4 in the series A Guide to Ruby Collections The first article in this series focused on Array and the basics of idiomatic Ruby iteration. Array is a pretty flexible class, but there are better solutions for particular situations. This article covers some of the other collection types that […]
This entry is part 1 of 4 in the series A Guide to Ruby Collections Programming consists largely of sorting and searching. In an older language like C, you might be expected to write your own data structures and algorithms for these tasks. However, with Ruby these constructs have been abstracted away in favor of […]
This article covers various ways that you can generate random (usually pseudo-random) information with Ruby. Random information can be useful for a variety of things, in particular testing, content generation, and security. I used Ruby 2.0.0, but 1.9 should produce the same results. Kernel#rand and Random In the past, a random range of numbers might […]
For the uninitiated, Wine (Wine Is Not an Emulator) is “a compatibility layer capable of running Windows applications on several POSIX-compliant operating systems, such as Linux, Mac OSX, and BSD.” It’s called “Not an Emulator” for a reason – instead of simulating an entire operating system in a virtual machine, it translates API calls in […]
We just started Unknowable Horror LLC. Our plan is sift through the vast ocean of bytes that is the internet in order to find the next H.P. Lovecraft so that we can make a fortune selling masterful cosmic horror. Alternatively, if we can’t find the next H.P. Lovecraft, we might just write our own stories […]