module Klam::Primitives::Strings

Public Instance Methods

"n->string"(n)
Alias for: n_to_string
"string->n"(str)
Alias for: string_to_n
cn(s1, s2) click to toggle source
# File lib/klam/primitives/strings.rb, line 18
def cn(s1, s2)
  s1 + s2
end
n_to_string(n) click to toggle source
# File lib/klam/primitives/strings.rb, line 45
def n_to_string(n)
  '' << n
end
Also aliased as: "n->string"
pos(str, n) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/klam/primitives/strings.rb, line 41
def string?(x)
  x.kind_of?(String)
end
string_to_n(str) click to toggle source
# File lib/klam/primitives/strings.rb, line 51
def string_to_n(str)
  str.ord
end
Also aliased as: "string->n"
tlstr(str) click to toggle source
# 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