Class: String

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

Overview

Extends the String class with additional functionality. This class adds methods to enhance string manipulation.

Examples:

Extending String functionality

my_string = "Hello"
my_string.stream = "stream_value"

Instance Method Summary collapse

Instance Method Details

#silentBoolean

Returns false, indicating that the string is not silent.

Examples:

puts "test string".silent # => false

Returns:

  • (Boolean)

    Always returns false.



107
108
109
# File 'documented/deprecated.rb', line 107

def silent
  false
end

#split_as_listArray<String>

Splits the string into a list based on specific patterns.

Examples:

result = "You notice a tree and a rock".split_as_list
puts result.inspect # => ["tree", "rock"]

Returns:

  • (Array<String>)

    An array of trimmed strings.



116
117
118
119
120
# File 'documented/deprecated.rb', line 116

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?

Retrieves the stream value associated with the string.

Examples:

Accessing the stream

my_string = "Hello"
my_string.stream # => nil

Returns:

  • (Object, nil)

    The stream value or nil if not set.



25
26
27
# File 'documented/common/class_exts/string.rb', line 25

def stream
  @stream
end

#stream=(val) ⇒ Object

Sets the stream value for the string if not already set.

Examples:

Setting the stream

my_string = "Hello"
my_string.stream = "stream_value"
puts my_string.stream # => "stream_value"

Parameters:

  • val (Object)

    The value to set as the stream.

Returns:

  • (Object)

    The value that was set as the stream.



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

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

#to_aArray<String>

Converts the string to an array containing the string itself.

Examples:

result = "hello world".to_a
puts result.inspect # => ["hello world"]

Returns:

  • (Array<String>)

    An array with the string as its only element.



99
100
101
# File 'documented/deprecated.rb', line 99

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

#to_sString

Returns a duplicate of the string.

Examples:

Duplicating a string

original = "Hello"
duplicate = original.to_s
puts duplicate # => "Hello"

Returns:

  • (String)

    A duplicate of the original string.



16
17
18
# File 'documented/common/class_exts/string.rb', line 16

def to_s
  self.dup
end