Class: String

Inherits:
Object show all
Defined in:
lib/user_input.rb

Overview

Adds the method from_user_input to various built-in classes as both a class and instance method. On a class, the method returns a validated instance of that class if it can be coerced into one (or nil if not). On an instance, it validates more strictly against the value of that instance.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_user_input(value) ⇒ Object

All strings validate as strings



7
8
9
# File 'lib/user_input.rb', line 7

def String.from_user_input(value)
	return value.to_s
end

Instance Method Details

#from_user_input(value) ⇒ Object

instance form does a straight comparison of the string with self.



12
13
14
15
16
17
18
# File 'lib/user_input.rb', line 12

def from_user_input(value)
	if (self == value.to_s)
		return value.to_s
	else
		return nil
	end
end