Module: Zoidberg::Shell

Defined in:
lib/zoidberg/shell.rb

Overview

Provides a wrapping around a real instance. Including this module within a class will enable magic.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Inject Shell magic into given class when included

Parameters:

  • klass (Class)


387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'lib/zoidberg/shell.rb', line 387

def self.included(klass)
  unless(klass.ancestors.include?(Zoidberg::Shell::InstanceMethods))
    klass.class_eval do

      class << self
        alias_method :unshelled_new, :new

        # Set an option or multiple options
        #
        # @return [Array<Symbol>]
        def option(*args)
          @option ||= []
          unless(args.empty?)
            @option += args
            @option.map!(&:to_sym).uniq!
          end
          @option
        end

        # Check if option is available
        #
        # @param arg [Symbol]
        # @return [TrueClass, FalseClass]
        def option?(arg)
          option.include?(arg.to_sym)
        end

      end

      include InstanceMethods
      extend ClassMethods
      include Bogo::Memoization
    end
  end
  unless(klass.include?(SoftShell) || klass.include?(HardShell))
    klass.class_eval do
      include Zoidberg.default_shell
    end
  end
end