Class: Magick::BinMagick::MagickWrapper
- Inherits:
-
Object
- Object
- Magick::BinMagick::MagickWrapper
- Defined in:
- lib/rmagick/bin_magick/magick_wrapper.rb
Overview
A wrapper around the “Magick::Image” class, providing a dynamic interface for forwarding method calls to the underlying “Magick::Image” object. When a method is called on “MagickWrapper”, it first checks if the underlying “Magick::Image” object responds to that method, and if so, it invokes the method on the object and returns the result.
If the result is another “Magick::Image” object, it wraps it in a new “MagickWrapper” object, allowing chaining of method calls.
If the result is not a “Magick::Image” object, it returns the result as is.
If the underlying “Magick::Image” object does not respond to the method, it raises a “NoMethodError”.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#image ⇒ Object
readonly
Returns the value of attribute image.
Instance Method Summary collapse
-
#initialize(image) ⇒ MagickWrapper
constructor
A new instance of MagickWrapper.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(image) ⇒ MagickWrapper
Returns a new instance of MagickWrapper.
21 22 23 24 25 |
# File 'lib/rmagick/bin_magick/magick_wrapper.rb', line 21 def initialize(image) raise BinMagick::DestroyedImageError, "Destroyed image" if image.destroyed? @image = image end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rmagick/bin_magick/magick_wrapper.rb', line 27 def method_missing(method_name, *args, &block) if @image.respond_to?(method_name) result = @image.send(method_name, *args, &block) if result.is_a?(Magick::Image) self.class.new(result) else result end else super end end |
Instance Attribute Details
#image ⇒ Object (readonly)
Returns the value of attribute image.
19 20 21 |
# File 'lib/rmagick/bin_magick/magick_wrapper.rb', line 19 def image @image end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
40 41 42 |
# File 'lib/rmagick/bin_magick/magick_wrapper.rb', line 40 def respond_to_missing?(method_name, include_private = false) @image.respond_to?(method_name) || super end |