Archive for 'methods'

Instance and Class Variable Accessor Methods

When you define classes in Ruby, you must specify what kind of access you want to give Instance and Class attributes/variables which are defined in that class. The way you do it is that you write reader and writer methods. You can write these methods out explicitly or use the shorthand attribute (attr_) methods like […]

Ruby Iterators

Here are some Ruby Iterators and description of how they can be used: times Iterate through the block 3 times, n starts at 0 and ends at 2 and is incremented by 1 each time. n is the block variable. upto Iterate through the block 3 times, starting at 1 and ending at 3, each […]

Ruby Require VS Load VS Include VS Extend

Here are the differences between Require, Load, Include and Extend methods: Include When you Include a module into your class as shown below, it’s as if you took the code defined within the module and inserted it within the class, where you ‘include’ it. It allows the ‘mixin’ behavior. It’s used to DRY up your […]

Ruby Time formatting and datetime SQL Column

If you’d like to format Time in Ruby, keep in mind that datetime SQL Columns translate to Time objects. So you can use the strftime method of the Time class to format the date/time. For example, assume scheduled_time is a field in your database and it has a sql data type of ‘datetime’. In your […]

What ruby and rails methods are available and where are they defined?

The Array class is in ruby core. It includes the Enumerable module so mixes in the methods defined there. However, there is also a Enumerable module defined in Rails. So, when using arrays you get both for free. How do you know when something is mixed in? How would I know I should also see […]