Module: Gamebox::Extensions::Object::Yoda

Included in:
Actor
Defined in:
lib/gamebox/lib/yoda.rb

Overview

This module behaves like the master jedi.

Instance Method Summary collapse

Instance Method Details

#do_or_do_not(name, *args) ⇒ Object? Also known as: yoda

Do or do not, there is no try. – Yoda.

Examples:

Do or do not.

object.do_or_do_not(:use, "The Force")

Parameters:

  • name (String, Symbol)

    The method name.

  • *args (Array)

    The arguments.

Returns:

  • (Object, nil)

    The result of the method call or nil if the method does not exist.

Since:

  • 2.0.0.rc.1



22
23
24
25
# File 'lib/gamebox/lib/yoda.rb', line 22

def do_or_do_not(name, *args)
  return nil unless name
  respond_to?(name) ? send(name, *args) : nil
end

#you_must(name, *args) ⇒ Object?

You must unlearn what you have learned. – Yoda

Examples:

You must perform this execution.

object.you_must(:use, "The Force")

Parameters:

  • name (String, Symbol)

    The method name.

  • *args (Array)

    The arguments.

Returns:

  • (Object, nil)

    The result of the method call or nil if the method does not exist. Nil if the object is frozen.

Since:

  • 2.2.1



40
41
42
# File 'lib/gamebox/lib/yoda.rb', line 40

def you_must(name, *args)
  frozen? ? nil : do_or_do_not(name, *args)
end