Class: Rational
- Defined in:
- lib/musa-dsl/core-ext/inspect-nice.rb,
lib/musa-dsl/core-ext/inspect-nice.rb,
lib/musa-dsl/core-ext/inspect-nice.rb
Instance Attribute Summary collapse
-
#to_s_as_inspect ⇒ Boolean?
Controls whether Rational#to_s uses inspect format.
Instance Method Summary collapse
-
#inspect(simple: nil) ⇒ String
Provides musical-friendly inspect output for Rational numbers.
-
#to_s ⇒ String
Provides string representation, format controlled by Rational.to_s_as_inspect.
Instance Attribute Details
#to_s_as_inspect ⇒ Boolean?
This attribute is added to Rational's singleton class via refinement. Requires using Musa::Extension::InspectNice.
Controls whether Rational#to_s uses inspect format.
When true: to_s displays detailed format (e.g., "1+1/4r") When false/nil: to_s displays simple format (e.g., "5/4")
116 |
# File 'lib/musa-dsl/core-ext/inspect-nice.rb', line 116 class ::Rational; end |
Instance Method Details
#inspect(simple: nil) ⇒ String
This method is added to Rational via refinement. Requires using Musa::Extension::InspectNice.
Provides musical-friendly inspect output for Rational numbers.
Two modes:
- Simple: Just numerator/denominator (e.g., "5/4", "2")
- Detailed: Mixed number with 'r' suffix (e.g., "1+1/4r", "2r")
The detailed format is particularly useful for musical time values, making expressions like "3+1/2r" (3.5 bars) immediately readable.
150 |
# File 'lib/musa-dsl/core-ext/inspect-nice.rb', line 150 class ::Rational; end |
#to_s ⇒ String
This method is added to Rational via refinement. Requires using Musa::Extension::InspectNice.
Provides string representation, format controlled by Rational.to_s_as_inspect.
Delegates to #inspect with the appropriate simple flag based on the global Rational.to_s_as_inspect setting.
171 |
# File 'lib/musa-dsl/core-ext/inspect-nice.rb', line 171 class ::Rational; end |