Class: Whitestone::Assertion::KindOf

Inherits:
Base show all
Defined in:
lib/whitestone/assertion_classes.rb

Overview

class Assertion::Match

Instance Method Summary collapse

Methods inherited from Base

#block

Methods included from Guards

#args_or_block_one_only, #block_required, #no_block_allowed, #one_argument, #two_arguments, #two_or_three_arguments, #type_check

Constructor Details

#initialize(mode, *args, &block) ⇒ KindOf

Returns a new instance of KindOf.



241
242
243
244
245
246
247
# File 'lib/whitestone/assertion_classes.rb', line 241

def initialize(mode, *args, &block)
  super
  no_block_allowed
  args = two_arguments(args)
  type_check(args, [Object,Module])
  @object, @klass = args
end

Instance Method Details

#messageObject



251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/whitestone/assertion_classes.rb', line 251

def message
  _not_ =
    case @mode
    when :assert then " "
    when :negate then " NOT "
    end
  Col.inline(
    "Type failure: object expected#{_not_}to be of type #{@klass}\n", :yb,
    "  Object's class is ",                                           :yb,
                         @object.class,                               :rb
  )
end

#runObject



248
249
250
# File 'lib/whitestone/assertion_classes.rb', line 248

def run
  @object.kind_of? @klass
end