Skip to content

Commit

Permalink
Merge pull request #31 from intercom/ruby-1.8
Browse files Browse the repository at this point in the history
ruby 1.8 alternative to define_singleton_method
  • Loading branch information
darragh committed Feb 11, 2013
2 parents d25142b + c0fecd1 commit bd8b9d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/intercom-rails/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ def self.config_accessor(*args, &block)
config_writer(*args, &block)
end

def self.meta_class
class << self; self end
end

def self.config_reader(name)
self.send(:define_singleton_method, name) do
meta_class.send(:define_method, name) do
instance_variable_get("@#{name}")
end
end

def self.config_writer(name, &block)
self.send(:define_singleton_method, "#{name}=") do |value|
meta_class.send(:define_method, "#{name}=") do |value|
block.call(value) if block && (block.arity <= 1)

if block && (block.arity > 1)
Expand All @@ -32,7 +36,7 @@ def self.config_group(name, &block)
camelized_name = name.to_s.classify
group = self.const_set(camelized_name, Class.new(self))

self.send(:define_singleton_method, name) do
meta_class.send(:define_method, name) do
group
end

Expand Down
2 changes: 1 addition & 1 deletion lib/intercom-rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module IntercomRails
VERSION = "0.2.14"
VERSION = "0.2.15"
end

0 comments on commit bd8b9d4

Please sign in to comment.