Class: Rigor::RbsExtended::PredicateEffect

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/rbs_extended.rb

Overview

Returned for ‘predicate-if-true` / `predicate-if-false`. `target_kind` is `:parameter` (with `target_name` the Ruby parameter symbol) or `:self`. `negative` is true when the directive uses the `~ClassName` form, in which case the engine narrows AWAY from `class_name` (`Narrowing.narrow_not_class`) instead of toward it.

‘refinement_type` is non-nil when the right-hand side is a kebab-case refinement name (`non-empty-string`, `lowercase-string`, …) instead of a Capitalised class name. The narrowing tier substitutes the carrier for the current local type; `class_name` is then nil and `negative` is false (refinement-form directives do not support `~T` negation in v0.0.4).

Instance Method Summary collapse

Instance Method Details

#falsey_only?Boolean

Returns:

  • (Boolean)


65
# File 'lib/rigor/rbs_extended.rb', line 65

def falsey_only? = edge == :falsey_only

#negative?Boolean

Returns:

  • (Boolean)


66
# File 'lib/rigor/rbs_extended.rb', line 66

def negative? = negative == true

#refinement?Boolean

Returns:

  • (Boolean)


67
# File 'lib/rigor/rbs_extended.rb', line 67

def refinement? = !refinement_type.nil?

#to_factObject

ADR-7 § “Slice 4-A” canonical translation. Lifts the parser-side carrier into a ‘Rigor::FlowContribution::Fact` that the merger and plugin contribution stream consume uniformly. `class_name` lifts to `Nominal`; `refinement_type` is already a `Rigor::Type` and passes through. The `edge` field doesn’t survive the conversion —the slot it lands in (truthy_facts / falsey_facts / …) encodes that.



77
78
79
80
81
82
83
84
# File 'lib/rigor/rbs_extended.rb', line 77

def to_fact
  FlowContribution::Fact.new(
    target_kind: target_kind,
    target_name: target_name,
    type: refinement_type || Rigor::Type::Combinator.nominal_of(class_name),
    negative: negative == true
  )
end

#truthy_only?Boolean

Returns:

  • (Boolean)


64
# File 'lib/rigor/rbs_extended.rb', line 64

def truthy_only? = edge == :truthy_only