Last active
August 29, 2015 14:05
-
-
Save sinankeskin/89e7a3eb98943138395b to your computer and use it in GitHub Desktop.
Hash Key'lerini metod ismi ile çağırmak - 2 - İyileştirme
This file contains 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 Hash | |
def method_missing(method_name) | |
if not respond_to?(method_name) | |
if has_key?(method_name) | |
self[method_name] | |
else | |
super.method_missing(method_name) | |
end | |
end | |
end | |
end | |
hash = {ad: 'Sinan', soyad: 'Keskin'} | |
puts hash.ad # Sinan | |
puts hash.adres # test.rb:7:in `method_missing': undefined method `adres' for {:ad=>"Sinan", :soyad=>"Keskin"}:Hash (NoMethodError)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment