Last active
December 21, 2015 18:29
-
-
Save acook/6347927 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
class SingleCharacterAttribtue | |
attr :my_single_character_attribute | |
def my_single_character_attribute = single_character | |
raise ArgumentError, "Expected single character, got #{single_character.length} characters." unless single_character.length = 1 | |
@mysingle_character_attribute = single_character | |
end | |
end | |
# usage | |
sca = SingleCharacterAttribute.new | |
puts sca.my_single_character_attribute #=> nil | |
sca.my_single_character_attribute = ?y # the question mark operator as used here makes the following character a single character string | |
puts sca.my_single_character_attribute #=> y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment