Skip to content

Instantly share code, notes, and snippets.

@jcoene
Created August 8, 2010 03:03

Revisions

  1. jcoene revised this gist Aug 8, 2010. 1 changed file with 5 additions and 13 deletions.
    18 changes: 5 additions & 13 deletions after_initizlialize_test.rb
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,10 @@ class RapSupahStah

    field :mode
    field :value

    def after_initialize

    after_initialize :my_after_initialize_callback

    def my_after_initialize_callback
    puts "after_initialize"
    puts "Using Mongoid: #{Mongoid::VERSION}"
    self.mode ||= "balla"
    @@ -28,14 +30,4 @@ def initialize(attributes={})
    end

    mongo_money = RapSupahStah.new
    puts mongo_money.mode

    ################
    # Output:
    ################
    # $ ruby after_initialize_test.rb
    # /Users/ryan/.rvm/gems/ruby-1.8.7-p299
    # initialize
    # Using Mongoid: 2.0.0.beta.16
    # pimp
    ################
    puts mongo_money.mode
  2. @rdetert rdetert created this gist Aug 8, 2010.
    41 changes: 41 additions & 0 deletions after_initizlialize_test.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    require 'rubygems'
    puts ENV["GEM_HOME"]
    require 'mongoid'
    require 'mongoid/version'

    class RapSupahStah
    include Mongoid::Document
    cache

    attr_accessor :mode

    field :mode
    field :value

    def after_initialize
    puts "after_initialize"
    puts "Using Mongoid: #{Mongoid::VERSION}"
    self.mode ||= "balla"
    end

    def initialize(attributes={})
    puts "initialize"
    puts "Using Mongoid: #{Mongoid::VERSION}"
    super
    self.mode ||= "pimp"
    end

    end

    mongo_money = RapSupahStah.new
    puts mongo_money.mode

    ################
    # Output:
    ################
    # $ ruby after_initialize_test.rb
    # /Users/ryan/.rvm/gems/ruby-1.8.7-p299
    # initialize
    # Using Mongoid: 2.0.0.beta.16
    # pimp
    ################