Last active
August 29, 2015 14:23
-
-
Save yuchan/505d5f016ff45bf5dd47 to your computer and use it in GitHub Desktop.
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
#! /usr/bin/env ruby | |
# | |
class Val | |
@@name = {} | |
attr_accessor :key | |
def initialize(key) | |
@@name[key] = key # 便宜上 | |
@key = key | |
end | |
def exec | |
@@name[@key] | |
end | |
def to_s | |
@key | |
end | |
end | |
val = Val.new("a") | |
val2 = Val.new("b") | |
val3 = Val.new("c") | |
puts val.exec | |
puts val2.exec | |
puts val3.exec | |
# -- output -- | |
# a | |
# b | |
# c |
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
#! /usr/bin/env ruby | |
# | |
class Val | |
attr_accessor :key | |
def initialize(key) | |
@@name = {} | |
@@name[key] = key # 便宜上 | |
@key = key | |
end | |
def exec | |
@@name[@key] | |
end | |
def to_s | |
@key | |
end | |
end | |
val = Val.new("a") | |
val2 = Val.new("b") | |
val3 = Val.new("c") | |
puts val.exec | |
puts val2.exec | |
puts val3.exec | |
# -- output -- | |
# | |
# | |
# c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment