Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/deprecated.rb,
lib/common/class_exts/string.rb

Overview

Carve out from lich.rbw extension to String class

Instance Method Summary collapse

Instance Method Details

#silentBoolean

Returns false, indicating that the string is not silent.

Examples:

"test".silent # => false

Returns:

  • (Boolean)

    always returns false.



105
106
107
# File 'lib/deprecated.rb', line 105

def silent
  false
end

#split_as_listArray<String>

Splits the string into a list based on specific patterns.

Examples:

"You notice a sword and a shield.".split_as_list # => ["sword", "shield"]

Returns:

  • (Array<String>)

    an array of trimmed strings after splitting.



114
115
116
117
118
# File 'lib/deprecated.rb', line 114

def split_as_list
  string = self
  string.sub!(/^You (?:also see|notice) |^In the .+ you see /, ',')
  string.sub('.', '').sub(/ and (an?|some|the)/, ', \1').split(',').reject { |str| str.strip.empty? }.collect { |str| str.lstrip }
end

#streamObject?

Returns the current stream value.

Examples:

str = "example"
str.stream # => nil

Returns:

  • (Object, nil)

    the current stream value or nil if not set.



22
23
24
# File 'lib/common/class_exts/string.rb', line 22

def stream
  @stream
end

#stream=(val) ⇒ Object

Note:

This method will only set the stream if it is currently nil.

Sets the stream value if it is not already set.

Examples:

str = "example"
str.stream = "new_stream" # => "new_stream"

Parameters:

  • val (Object)

    the value to set as the stream.

Returns:

  • (Object)

    the value that was set as the stream.



36
37
38
# File 'lib/common/class_exts/string.rb', line 36

def stream=(val)
  @stream ||= val
end

#to_aArray<String>

Converts the string to an array for compatibility with Ruby 1.8.

Examples:

"hello".to_a # => ["hello"]

Returns:

  • (Array<String>)

    an array containing the string.



96
97
98
# File 'lib/deprecated.rb', line 96

def to_a # for compatibility with Ruby 1.8
  [self]
end

#to_sString

Returns a duplicate of the string.

Examples:

"hello".to_s # => "hello"

Returns:

  • (String)

    a duplicate of the original string.



11
12
13
# File 'lib/common/class_exts/string.rb', line 11

def to_s
  self.dup
end