Created
May 25, 2011 09:01
-
-
Save lvillasica/990628 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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