Skip to content

Instantly share code, notes, and snippets.

@timothyklim
Created April 3, 2011 07:55
Show Gist options
  • Save timothyklim/900271 to your computer and use it in GitHub Desktop.
Save timothyklim/900271 to your computer and use it in GitHub Desktop.
small expose
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