Skip to content

Instantly share code, notes, and snippets.

@Narnach
Forked from samaaron/gist:46396
Created January 13, 2009 10:55
Show Gist options
  • Save Narnach/46402 to your computer and use it in GitHub Desktop.
Save Narnach/46402 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'active_support'
class John
end
j_c = John.class_eval do
def hi
'hi'
end
class << self
def friendly_param(parameter_name)
cattr_accessor :friendly_param
self.friendly_param = parameter_name.to_s
end
end
self
end
j_i = John.instance_eval do
def hi
'yo'
end
class << self
def friendly_param(parameter_name)
cattr_accessor :friendly_param
self.friendly_param = parameter_name.to_s
end
end
self
end
puts j_c == j_i #=> true
John.friendly_param :beans
puts John.friendly_param #=> beans
puts John.new.hi #=> hi
puts John.friendly_param #=> beans
puts John.hi #=> yo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment