Class: String19::Wrapper

Inherits:
BlankSlate show all
Defined in:
lib/string19.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wrapped) ⇒ Wrapper

Returns a new instance of Wrapper.



17
18
19
# File 'lib/string19.rb', line 17

def initialize(wrapped)
  @chars = wrapped.scan(/./m)
end

Instance Attribute Details

#charsObject (readonly)

Returns the value of attribute chars.



15
16
17
# File 'lib/string19.rb', line 15

def chars
  @chars
end

Instance Method Details

#==(other) ⇒ Object



45
46
47
48
# File 'lib/string19.rb', line 45

def ==(other)
  other = other.to_s18 if other.is_a?(String19::Wrapper)
  other.is_a?(String) and to_s18 == other
end

#bytesObject



29
30
31
# File 'lib/string19.rb', line 29

def bytes
  to_s18.bytes
end

#bytesizeObject



25
26
27
# File 'lib/string19.rb', line 25

def bytesize
  to_s18.size
end

#classObject



37
38
39
# File 'lib/string19.rb', line 37

def class
  String
end

#encodingObject



33
34
35
# File 'lib/string19.rb', line 33

def encoding
  Encoding.new('UTF-8')
end

#index(what, offset = 0) ⇒ Object



62
63
64
65
66
67
# File 'lib/string19.rb', line 62

def index(what, offset=0)
  s = to_s18
  offset = self[0...offset].to_s18.size
  return unless found = s.index(what, offset)
  String19(s[0...found]).size
end

#is_a?(klass) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/string19.rb', line 41

def is_a?(klass)
  [String19::Wrapper, String, Object].include?(klass)
end

#to_sObject



50
51
52
# File 'lib/string19.rb', line 50

def to_s
  self
end

#to_s18Object



54
55
56
# File 'lib/string19.rb', line 54

def to_s18
  @chars.to_s
end

#valid_encoding?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/string19.rb', line 58

def valid_encoding?
  true # i hope so :P
end