Sha256: d28b7fe7a1dbb952c0bfa87262b5410066cac20849f0806c75add039094581ec

Contents?: true

Size: 933 Bytes

Versions: 9

Compression:

Stored size: 933 Bytes

Contents

class Object
  # Tries the given methods and returns the first one to return a value,
  # ultimately returns nil if no value is found.
  def try(*methods)
    methods.each do |method|
      if respond_to?(method)
        val = send(method)
        return val if val
      end
    end
    nil
  end

  # Indicates whether the object is or can be used as an Origen subblock, where
  # being an Origen subblock is defined as inheriting from either {Origen::Model} or
  # {Origen::Controller}.
  # @return [True/False]
  # @example Subblock NVM (from the Origen guides)
  #   dut.nvm.origen_subblock? #=> true
  # @example Non-subblocks
  #   'hi'.origen_subblock? #=> false
  # @see https://origen-sdk.org/origen/guides/models/defining/#Adding_Sub_Blocks
  def origen_subblock?
    is_a?(Origen::Model) || is_a?(Origen::Controller) || is_a?(Origen::SubBlocks::Placeholder)
  end
  alias_method :origen_sub_block?, :origen_subblock?
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
origen-0.60.17 lib/origen/core_ext/object.rb
origen-0.60.16 lib/origen/core_ext/object.rb
origen-0.60.14 lib/origen/core_ext/object.rb
origen-0.60.13 lib/origen/core_ext/object.rb
origen-0.60.12 lib/origen/core_ext/object.rb
origen-0.60.11 lib/origen/core_ext/object.rb
origen-0.60.10 lib/origen/core_ext/object.rb
origen-0.60.9 lib/origen/core_ext/object.rb
origen-0.60.8 lib/origen/core_ext/object.rb