Sha256: d49338aeba1c86d8f901f15bebaa8a22efef4f5290b329f932c4c4e8f6998dcb

Contents?: true

Size: 884 Bytes

Versions: 10

Compression:

Stored size: 884 Bytes

Contents

#
# must.rb
#
#   Copyright (c) 1999-2002 Minero Aoki <aamine@loveruby.net>
#
#   This program is free software.
#   You can distribute/modify this program under the terms of
#   the GNU Lesser General Public License version 2 or later.
#
#   $Id: must.rb,v 1.12 2002/01/05 06:19:34 aamine Exp $
#
class Object

  def must( *args )
    args.each {|c| return self if c === self }
    raise TypeError, "wrong arg type '#{self.class}' for required #{args.join('/')}"
  end

  def must_have( *args )
    args.each do |m|
      self.respond_to? m or
        raise ArgumentError, "receiver #{inspect} does not have '#{m}'"
    end
    self
  end
  alias_method :needed, :must_have

  def must_be( obj )
    self == obj or raise ArgumentError, "expected #{eq.inspect} but is #{inspect}"
    self
  end

  def must_exist
    nil? and raise ArgumentError, 'receiver is wrongly nil'
  end

end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
carats-0.3.0 lib/carat-dev/interface_work/must.rb
facets-1.4.2 forge/more/must.rb
facets-1.4.1 forge/more/must.rb
facets-1.4.3 forge/more/must.rb
facets-1.4.5 snip/more/must.rb
facets-1.4.4 forge/more/must.rb
facets-1.8.0 work/more/must.rb
facets-1.8.20 work/more/must.rb
facets-1.8.49 work/more/must.rb
facets-1.8.8 work/more/must.rb