Skip to content

Instantly share code, notes, and snippets.

@acook
Last active December 21, 2015 18:29
Show Gist options
  • Save acook/6347927 to your computer and use it in GitHub Desktop.
Save acook/6347927 to your computer and use it in GitHub Desktop.
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