Module: Klam::Primitives::Strings
- Included in:
- Environment
- Defined in:
- lib/klam/primitives/strings.rb
Instance Method Summary collapse
- #cn(s1, s2) ⇒ Object
- #n_to_string(n) ⇒ Object (also: #n->string)
- #pos(str, n) ⇒ Object
- #str(x) ⇒ Object
- #string?(x) ⇒ Boolean
- #string_to_n(str) ⇒ Object (also: #string->n)
- #tlstr(str) ⇒ Object
Instance Method Details
#cn(s1, s2) ⇒ Object
18 19 20 |
# File 'lib/klam/primitives/strings.rb', line 18 def cn(s1, s2) s1 + s2 end |
#n_to_string(n) ⇒ Object Also known as: n->string
45 46 47 |
# File 'lib/klam/primitives/strings.rb', line 45 def n_to_string(n) '' << n end |
#pos(str, n) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/klam/primitives/strings.rb', line 4 def pos(str, n) if n < 0 || n >= str.length ::Kernel.raise ::Klam::Error, "index out of bounds: #{n}" end str[n] end |
#str(x) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/klam/primitives/strings.rb', line 22 def str(x) case x when String '"' + x + '"' when Symbol x.to_s when Numeric x.to_s when TrueClass, FalseClass x.to_s when Proc x.to_s when IO x.to_s else ::Kernel.raise ::Klam::Error, "str applied to non-atomic type: #{x.class}" end end |
#string?(x) ⇒ Boolean
41 42 43 |
# File 'lib/klam/primitives/strings.rb', line 41 def string?(x) x.kind_of?(String) end |
#string_to_n(str) ⇒ Object Also known as: string->n
51 52 53 |
# File 'lib/klam/primitives/strings.rb', line 51 def string_to_n(str) str.ord end |