Class: Build2Spec::UnknownType
Constant Summary
collapse
- @@name_suffix =
"A"
- @@guessing_table =
[
[Fixnum, '42'],
[String, '"wrong answer"'],
[Array, '[]'],
[Hash, '{}'],
[Object, "Object.new"],
[Class, @name],
]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
current_method, #initialize, #method_missing, record_method_spec, unknown_types
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Build2Spec::FakingMethods
Instance Attribute Details
Returns the value of attribute name.
504
505
506
|
# File 'lib/build2spec.rb', line 504
def name
@name
end
|
Returns the value of attribute standin.
504
505
506
|
# File 'lib/build2spec.rb', line 504
def standin
@standin
end
|
Class Method Details
.add_guess_entry(klass, exemplar) ⇒ Object
477
478
479
|
# File 'lib/build2spec.rb', line 477
def self.add_guess_entry(klass, exemplar)
@@guessing_table.unshift [klass, exemplar]
end
|
.create(nesting, name = nil) ⇒ Object
481
482
483
484
485
|
# File 'lib/build2spec.rb', line 481
def self.create(nesting, name = nil)
type = self.allocate
type.setup(nesting, name)
type
end
|
Instance Method Details
#faked_methods ⇒ Object
573
574
575
|
# File 'lib/build2spec.rb', line 573
def faked_methods
@standin.faked_instance_methods
end
|
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
|
# File 'lib/build2spec.rb', line 526
def guess
if @guess.nil?
if standin.empty?
return "nil"
else
init_spec = @standin.faked_instance_methods[:initialize]
if init_spec.nil?
return "#@name.new"
else
return "#@name.new#{@standin.argument_text(init_spec)}"
end
end
else
return @guess
end
end
|
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
# File 'lib/build2spec.rb', line 506
def guess!
return if faked_methods.empty?
return if guessed?
@@guessing_table.each do |klass, exemplar|
faked = faked_methods.map{|f| f[0].to_s}
klass.instance_methods.each do |real|
faked.delete(real)
end
if(faked.empty?)
@guess = exemplar
return
end
end
end
|
#guessed? ⇒ Boolean
522
523
524
|
# File 'lib/build2spec.rb', line 522
def guessed?
not @guess.nil?
end
|
#im_a_module ⇒ Object
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
|
# File 'lib/build2spec.rb', line 549
def im_a_module
return @instance_type unless @instance_type.nil?
module_standin = UnknownStandIn.new(self)
@standin.faked_instance_methods.each_pair do |k,v|
module_standin.faked_module_methods[k] = v
end
@standin = module_standin
class << self
def faked_methods
@standin.faked_module_methods
end
def guess!
end
end
@instance_type = UnknownType.create(@nesting, @name)
@name += "Class"
@guess = nil
return @instance_type
end
|
500
501
502
|
# File 'lib/build2spec.rb', line 500
def inspect
"<Build2Spec Dummy Return Value>"
end
|
#new(*args, &block) ⇒ Object
543
544
545
546
547
|
# File 'lib/build2spec.rb', line 543
def new(*args, &block)
instance = im_a_module
instance.initialize(*args, &block)
return instance
end
|
#return_type_nesting ⇒ Object
577
578
579
|
# File 'lib/build2spec.rb', line 577
def return_type_nesting
@nesting
end
|
#setup(nesting, name) ⇒ Object
491
492
493
494
495
496
497
498
|
# File 'lib/build2spec.rb', line 491
def setup(nesting, name)
@standin = UnknownStandIn.new(self)
@guess = nil
@name = name || "UnknownType#{@@name_suffix}"
@nesting = nesting
@@name_suffix.succ!
Builder::add_standin(nesting, @name, @standin)
end
|
#superclass ⇒ Object
487
488
489
|
# File 'lib/build2spec.rb', line 487
def superclass
Object
end
|