Sha256: 868efeb94b3a3874435f922186fc20524f4d2648505e110409364280bd8b7d6c

Contents?: true

Size: 953 Bytes

Versions: 36

Compression:

Stored size: 953 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 self.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?
    self.is_a?(Origen::Model) || self.is_a?(Origen::Controller) || self.is_a?(Origen::SubBlocks::Placeholder)
  end
  alias_method :origen_sub_block?, :origen_subblock?
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
origen-0.60.7 lib/origen/core_ext/object.rb
origen-0.60.6 lib/origen/core_ext/object.rb
origen-0.60.5 lib/origen/core_ext/object.rb
origen-0.60.4 lib/origen/core_ext/object.rb
origen-0.60.3 lib/origen/core_ext/object.rb
origen-0.60.2 lib/origen/core_ext/object.rb
origen-0.60.1 lib/origen/core_ext/object.rb
origen-0.60.0 lib/origen/core_ext/object.rb
origen-0.59.8 lib/origen/core_ext/object.rb
origen-0.59.7 lib/origen/core_ext/object.rb
origen-0.59.6 lib/origen/core_ext/object.rb
origen-0.59.5 lib/origen/core_ext/object.rb
origen-0.59.4 lib/origen/core_ext/object.rb
origen-0.59.3 lib/origen/core_ext/object.rb
origen-0.59.2 lib/origen/core_ext/object.rb
origen-0.59.1 lib/origen/core_ext/object.rb
origen-0.59.0 lib/origen/core_ext/object.rb
origen-0.58.0 lib/origen/core_ext/object.rb
origen-0.57.2 lib/origen/core_ext/object.rb
origen-0.57.1 lib/origen/core_ext/object.rb