This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
attr_accessor :first_name, :last_name, :birthday | |
end | |
# Results | |
# user = User.new | |
# user.first_name = "Vinh" | |
# user.first_name => "Vinh" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
attr_accessor :first_name, :last_name, :birthday | |
end | |
# Results | |
# user = User.new | |
# user.middle_name ==> NoMethodError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
attr_accessor :first_name, :last_name, :birthday | |
# method_missing() is passed 2 arguments: name of the missing method and arrays of its arguments | |
# reference at the link: http://www.ruby-doc.org/core-2.1.0/BasicObject.html#method-i-method_missing | |
def method_missing(name, *arg) | |
puts "#{name} was called with arguments: #{arg.join(',')}. #{name} method not available." | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Question | |
def get_question_title | |
puts "get_question_title called" | |
end | |
def get_question_content | |
puts "get_question_content called" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ==================== | |
# Spell: Dynamic Proxy | |
# ==================== | |
# Forward to another object any messages that don’t match a method. | |
class MyDynamicProxy | |
def initialize(target) | |
@target = target | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.generators.stylesheet_engine = :sass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DefaultValues | |
def has_default_values(default_values = {}) | |
class_attribute :default_values | |
self.default_values = default_values | |
after_initialize :assign_default_values | |
include InstanceMethods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddNameToUser < ActiveRecord::Migration | |
def self.up | |
add_column :users, :name, :string | |
User.reset_column_information | |
User.find(:all).each do |user| | |
user.name = user.first_name + ' ' + user.last_name | |
end | |
remove_column :users, :first_name | |
remove_column :users, :last_name | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
validate_inclusion_of :activation_state, :in => ["pending", "active"] | |
def self.pending_users | |
find :all, :conditions => {:activation_state => 'pending'} | |
end | |
def self.active_users | |
find :all, :conditions => {:activation_state => 'active'} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% unless @contacts.nil?%> | |
<% @contacts.each do |c|%> | |
<ul> | |
<li><%= c[:name]%> : <%= c[:email]%></li> | |
</ul> | |
<%end%> | |
<%end%> |
OlderNewer