Created
April 3, 2011 07:55
-
-
Save timothyklim/900271 to your computer and use it in GitHub Desktop.
small expose
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
require 'active_support/all' | |
class Yeah | |
def initialize | |
@params = {"university_id" => 2, "id" => 3} | |
end | |
def method_missing(name, *args) | |
if name.to_s =~ /^find_([a-z]+)_id$/ | |
find_id($1) | |
else | |
super | |
end | |
end | |
def find_id(name) | |
id = @params["#{name}_id"].presence || @params["id"] | |
instance_eval "@#{name} = #{id}" | |
end | |
end | |
@t = Yeah.new | |
@t.find_university_id | |
@t.instance_eval do | |
puts "University: #{@university}" | |
end | |
@t.find_yeah_id | |
@t.instance_eval do | |
puts "Yeah: #{@yeah}" | |
end | |
class YeahController < Yeah | |
# before_filter :find_university_id | |
def index | |
find_university_id | |
puts "University id is #{@university}" | |
end | |
end | |
YeahController.new.index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment