Skip to content

Commit

Permalink
Support core extensions were clashing with Rails's so namespaced them.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Gilbraith committed Jun 11, 2009
1 parent 6d65ad8 commit 1d26b8f
Showing 1 changed file with 51 additions and 47 deletions.
98 changes: 51 additions & 47 deletions lib/amazon_product_advertising_api/support.rb
@@ -1,55 +1,59 @@
class Class
def cattr_reader(sym)
class_eval(<<-EOS, __FILE__, __LINE__)
unless defined? @@#{sym} # unless defined? @@hair_colors
@@#{sym} = nil # @@hair_colors = nil
end # end
#
def self.#{sym} # def self.hair_colors
@@#{sym} # @@hair_colors
end # end
#
def #{sym} # def hair_colors
@@#{sym} # @@hair_colors
end # end
EOS
end
module AmazonProductAdvertisingApi

class Class
def cattr_reader(sym)
class_eval(<<-EOS, __FILE__, __LINE__)
unless defined? @@#{sym} # unless defined? @@hair_colors
@@#{sym} = nil # @@hair_colors = nil
end # end
#
def self.#{sym} # def self.hair_colors
@@#{sym} # @@hair_colors
end # end
#
def #{sym} # def hair_colors
@@#{sym} # @@hair_colors
end # end
EOS
end

def cattr_writer(sym)
class_eval(<<-EOS, __FILE__, __LINE__)
unless defined? @@#{sym} # unless defined? @@hair_colors
@@#{sym} = nil # @@hair_colors = nil
end # end
#
def self.#{sym}=(obj) # def self.hair_colors=(obj)
@@#{sym} = obj # @@hair_colors = obj
end # end
EOS
end
def cattr_writer(sym)
class_eval(<<-EOS, __FILE__, __LINE__)
unless defined? @@#{sym} # unless defined? @@hair_colors
@@#{sym} = nil # @@hair_colors = nil
end # end
#
def self.#{sym}=(obj) # def self.hair_colors=(obj)
@@#{sym} = obj # @@hair_colors = obj
end # end
EOS
end

def cattr_accessor(sym)
cattr_reader(sym)
cattr_writer(sym)
end

def cattr_accessor(sym)
cattr_reader(sym)
cattr_writer(sym)
end

end

class String
class String

def camelize(first_letter_in_uppercase = true)
if first_letter_in_uppercase
self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
else
self.first + camelize(self)[1..-1]
def camelize(first_letter_in_uppercase = true)
if first_letter_in_uppercase
self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
else
self.first + camelize(self)[1..-1]
end
end
end

def underscore
self.to_s.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
end

def underscore
self.to_s.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
end

end

end

0 comments on commit 1d26b8f

Please sign in to comment.