Class: String

Inherits:
Object show all
Includes:
Symbolic
Defined in:
lib/moon/packages/std/core_ext/string.rb,
lib/moon/packages/std/core_ext/symbolic.rb,
lib/moon/packages/micro_json/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Determines if the string is empty, or filled with whitespace.

Returns:

  • (Boolean)

    whether the string is blank


7
8
9
10
11
# File 'lib/moon/packages/std/core_ext/string.rb', line 7

def blank?
  return true if empty?
  return true if strip.empty?
  false
end

#indent(n) ⇒ String

Returns an indented string

Parameters:

Returns:


24
25
26
27
28
29
30
# File 'lib/moon/packages/std/core_ext/string.rb', line 24

def indent(n)
  result = ''
  self.each_line do |line|
    result << (' ' * n) +  line
  end
  result
end

#presenceself?

Returns nil if the string is #blank?, otherwise self

Returns:

  • (self, nil)

16
17
18
# File 'lib/moon/packages/std/core_ext/string.rb', line 16

def presence
  blank? ? nil : self
end

#to_jsonString

Dumps the Strings as a JSON string.

Returns:


5
6
7
# File 'lib/moon/packages/micro_json/core_ext/string.rb', line 5

def to_json
  JSON.dump(self)
end