Class: Colorize::Extended::BackgroundProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/colorize/extended/background_proxy.rb

Overview

Proxy object returned by String#on that forwards color method calls as background color applications.

Example:

"hello".red.on.blue  # equivalent to "hello".red.on_blue

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ BackgroundProxy

Returns a new instance of BackgroundProxy.



13
14
15
# File 'lib/colorize/extended/background_proxy.rb', line 13

def initialize(string)
  @string = string
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/colorize/extended/background_proxy.rb', line 17

def method_missing(name, *args, &block)
  on_method = :"on_#{name}"
  if @string.respond_to?(on_method)
    @string.send(on_method, *args, &block)
  else
    super
  end
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/colorize/extended/background_proxy.rb', line 26

def respond_to_missing?(name, include_private = false)
  @string.respond_to?(:"on_#{name}", include_private) || super
end