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 Momoro < ActiveRecord::Base | |
def food | |
ActiveSupport::StringInquirer.new("#{read_attribute(:food)}") | |
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
def env | |
@_env ||= begin | |
require 'active_support/string_inquirer' | |
ActiveSupport::StringInquirer.new(RAILS_ENV) | |
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
# It doesn't work this way! | |
>> m = Momoro.new | |
=> #<Momoro id: nil, name: nil, food: nil, created_at: nil, updated_at: nil> | |
>> m.food = "basil" | |
>> m.food.basil? | |
=> true | |
>> m.food = "pillows" | |
>> m.food.pillows? |
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 Momoro < ActiveRecord::Base | |
def food | |
ActiveSupport::StringInquirer.new("basil") | |
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
=> #<Momoro id: 5, name: nil, food: nil, created_at: "2008-12-09 07:38:34", updated_at: "2008-12-09 07:38:34"> | |
>> m.food | |
=> "basil" | |
>> m.read_attribute(:food) | |
=> nil |
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
>> m = Momoro.new | |
=> #<Momoro id: nil, name: nil, food: nil, created_at: nil, updated_at: nil> | |
>> m.food = "basil" | |
=> "basil" | |
>> m.food.basil? | |
method name = basil? | |
method_name.to_s[-1,1] = ? | |
self = basil | |
method_name.to_s[0..-2] = basil | |
=> true |
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 Momoro < ActiveRecord::Base | |
def food | |
ActiveSupport::StringInquirer.new(read_attribute(:food)) | |
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
if [child, parent, grandpa, president, food, ink].all{|e| e.valid?} | |
... #do stuff | |
end | |
>> %w{foo, bar, baz}.all?{|e| e.is_a?(String)} | |
=> true | |
>> ["foo", "bar", 1].all?{|e| e.is_a?(String)} | |
=> false |
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
#(Thanks to Thomas Ritz, http://www.galaxy-ritz.de ,for the code.) | |
namespace :doc do | |
namespace :diagram do | |
task :models do | |
sh "railroad -i -l -a -m -M | dot -Tsvg | sed 's/font-size:14.00/font-size:11.00/g' > doc/models.svg" | |
end | |
task :controllers do | |
sh "railroad -i -l -C | neato -Tsvg | sed 's/font-size:14.00/font-size:11.00/g' > doc/controllers.svg" |
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 FlashHelper | |
def flashes | |
{:partial => '/forms/flashes', :object => flash} | |
end | |
def flash_names | |
[:notice, :error, :message, :success] | |
end | |