Module: PlainText::Part::StringType

Included in:
Boundary, Paragraph
Defined in:
lib/plain_text/part/string_type.rb

Overview

Contains common methods for use in the String-type classes.

Author:

  • Masa Sakano (Wise Babel Ltd)

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **kwds) ⇒ Object

Basically delegates everything to String



22
23
24
25
# File 'lib/plain_text/part/string_type.rb', line 22

def method_missing(method_name, *args, **kwds)
  ret = to_s.public_send(method_name, *args, **kwds)
  ret.respond_to?(:to_str) ? self.class.new(ret) : ret
end

Instance Method Details

#clonePlainText::Part

Work around because Object#clone does not clone the instance variable @string

Returns:



71
72
73
# File 'lib/plain_text/part/string_type.rb', line 71

def clone
  dup_or_clone(super, __method__, '@string') # defined in builtin_type.rb
end

#dupPlainText::Part

Work around because Object#dup does not dup the instance variable @string

Returns:



64
65
66
# File 'lib/plain_text/part/string_type.rb', line 64

def dup
  dup_or_clone(super, __method__, '@string') # defined in builtin_type.rb
end

#inspectString

Para(“abncd”) or Boundary(“nnn”)

Returns:



35
36
37
38
# File 'lib/plain_text/part/string_type.rb', line 35

def inspect
  s = self.class.name
  sprintf "%s(%s)", (s.split('::')[2..-1].join('::') rescue s), to_s.inspect
end

#respond_to_missing?(method_name, *rest) ⇒ Boolean

Redefines the behaviour of respond_to? (essential when defining method_missing)

Returns:

  • (Boolean)


28
29
30
# File 'lib/plain_text/part/string_type.rb', line 28

def respond_to_missing?(method_name, *rest)  # include_all=false
  to_s.respond_to?(method_name, *rest) || super
end

#to_sString Also known as: to_str, instance

Returns:



15
16
17
# File 'lib/plain_text/part/string_type.rb', line 15

def to_s
  @string
end