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
permalink #cn(s1, s2) ⇒ Object
[View source]
18 19 20 |
# File 'lib/klam/primitives/strings.rb', line 18 def cn(s1, s2) s1 + s2 end |
permalink #n_to_string(n) ⇒ Object Also known as: n->string
[View source]
45 46 47 |
# File 'lib/klam/primitives/strings.rb', line 45 def n_to_string(n) '' << n end |
permalink #pos(str, n) ⇒ Object
[View source]
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 |
permalink #str(x) ⇒ Object
[View source]
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 |
permalink #string?(x) ⇒ Boolean
41 42 43 |
# File 'lib/klam/primitives/strings.rb', line 41 def string?(x) x.kind_of?(String) end |
permalink #string_to_n(str) ⇒ Object Also known as: string->n
[View source]
51 52 53 |
# File 'lib/klam/primitives/strings.rb', line 51 def string_to_n(str) str.ord end |
permalink #tlstr(str) ⇒ Object
[View source]
11 12 13 14 15 16 |
# File 'lib/klam/primitives/strings.rb', line 11 def tlstr(str) if str.empty? ::Kernel.raise ::Klam::Error, 'attempted to take tail of empty string' end str[1..-1] end |