Skip to content

Careful what you memoize

Memoizing class methods is an anti-pattern: http://cmme.org/tdumitrescu/blog/2014/01/careful-what-you-memoize/

Advertisements

Module#prepend

This explains prepend:

class ParentClass
  def log
    puts "In parent"
  end
end

module ExtraMessageLogging
  def log
    puts "In child, with extra message"
    super
  end
end

class ChildClass < ParentClass
  prepend ExtraMessageLogging
  def log
    puts "In child"
    super
  end
end

In child, with extra message
In child
In parent

This is picked up from : http://www.justinweiss.com/blog/2014/09/08/rails-5-module-number-prepend-and-the-end-of-alias-method-chain/

Helpful blog post on rake parameters

http://itshouldbeuseful.wordpress.com/2011/11/07/passing-parameters-to-a-rake-task/

Rails.application and Desiringgod::Application

“`

> Rails.application.class
=> Desiringgod::Application

“`

Automatically join channels in colloquy

To automatically join channels in colloquy:

1. Go to your connections window

2. Select the connection in question

3. Click the info icon

4. Click the ‘automatic’ tab

5. use the command: 

6. Select connect on launch

7. Paste in the JOIN command to join the channels you want to auto-join each time. Example: 

`

JOIN #mac,#redis,#colloquy,#ruby

JOIN #machomebrew,#github,#devise

`

 

 

 

three state boolean logic

Three state boolean logic should be avoided. http://robots.thoughtbot.com/avoid-the-threestate-boolean-problem


2.1.0 :008 > true and false
=> false
2.1.0 :009 > true and nil
=> nil
2.1.0 :013 > false or false
=> false
2.1.0 :014 > false or nil
=> nil

Date.current V/S Date.today

I recently hit some strangeness when working with Rails:

(rdb:1) Date.yesterday
Thu, 31 Oct 2013
(rdb:1) Date.today
Thu, 31 Oct 2013
(rdb:1) Date.tomorrow
Sat, 02 Nov 2013
Turns out that Date.today is picking up today’s date from GMT and not from the local zone.  It requires using Date.current.
Check out this discussion on a rails issue here: https://github.com/rails/rails/issues/759