extend adds class methods too

lazylester Sep 9, 2009 1 thank

Because classes are objects. So for example:

module Ispeak
  def says
    "greetings aliens!"
  end
end

module Ieat
  def eats
    "spinach"
  end
end

module Inhabitant
  def says
    "I'm strong to the finish"
  end
end

class H...

session expiration

annaswims Sep 1, 2009 1 thank

If you need to set expiration period for sessions through all controllers in your application, simply add the following option to your config/intializers/session_store.rb file: :expire_after => 60.minutes If you need to set different expiration time in different controllers or actions, use the f...

Passing an :object to the partial

wyrmmage Aug 26, 2009

For some reason the :object option is completely undocumented. Here's an example usage.

Renders the partial, making @new_person available through the local variable 'person'

render :partial => "person", :object => @new_person

(Credit goes to Catfish for the example, which I obtained from http:...

Getting (n..end)

Mange Aug 24, 2009 1 thank

It would seem like it would be possible to say, get everything from element i and to the end by saying # WRONG! a[i, -1] # "From 2 to the last element"

but since the second parameter does not say the ending index, but instead the length, this is not possible and you will get nil from the ab...

Freezing Time.now with Time.is

hosiawak Aug 17, 2009 1 thank

Sometimes when writing unit tests/specifications our code sets an attribute of an object using Time.now because running specs/test takes time.

The solution is to "freeze" Time.now with the following Time.is method:

class Time

 def self.metaclass
   class << self; self; end
 end...

Time in fixtures

hosiawak Aug 17, 2009 2 thanks

When creating fixtures you should use this method to set created_at/updated_at timestamps correctly:

eg:

This won't work as expected (created_at/updated_at will be nil) a one: episode: active1 play_id: 1 play_time: 20 country: United Kingdom created_at: <%= Time.parse('...

Time in fixtures

hosiawak Aug 17, 2009 1 thank

When creating fixtures you should use this method to set created_at/updated_at timestamps correctly:

eg:

This won't work as expected (created_at/updated_at will be nil) a one: episode: active1 play_id: 1 play_time: 20 country: United Kingdom created_at: <%= Time.parse('...