Skip to content

Instantly share code, notes, and snippets.

@lvillasica
Created May 25, 2011 09:01
Show Gist options
  • Save lvillasica/990628 to your computer and use it in GitHub Desktop.
Save lvillasica/990628 to your computer and use it in GitHub Desktop.
class A
def initialize
@a = 11
@@a = 22
end
@a = 1
@@a = 2
end
puts A.instance_variable_get(:@a)
puts A.class_variable_get(:@@a)
a = A.new
puts a.instance_variable_get(:@a)
puts A.class_variable_get(:@@a)
class I
def like arg
puts "%s %s %s" % [self.class, self.class.instance_methods(false), arg]
end
end
c, m, arg = gets.split # input 'I like metaprogramming.'
i = I.new
i.like(arg)
var = class A
@@a = 1
@a = 2
a = 3
# Write your code here. Use binding method.
binding
end
puts eval('[@@a, @a, a]', var).inspect # Replace '*****' to your code
String.class_eval do
def tr_vowel
tr 'aeiou', '*'
end
def self.tr_vowel str
str.tr 'aeiou', '*'
end
end
puts "hello".tr_vowel
puts String.tr_vowel "hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment