Module: Uniword::Properties::BooleanValSetter
- Included in:
- Customxml::ShowingPlaceholder, DocumentVariables::ReadOnly, Glossary::AutoText, Glossary::Equation, Glossary::TextBox, AdjustRightInd, AutoSpaceDE, AutoSpaceDN, Bold, BoldCs, Caps, ContextualSpacing, DoubleStrike, Emboss, Imprint, Italic, ItalicCs, KeepLines, KeepNext, NoProof, PageBreakBefore, QuickFormat, Shadow, SmallCaps, Strike, Vanish, WebHidden, WidowControl, SharedTypes::BooleanValue, SharedTypes::OnOff, Wordprocessingml::Emboss, Wordprocessingml::Imprint, Wordprocessingml::Outline, Wordprocessingml::Shadow
- Defined in:
- lib/uniword/properties/boolean_formatting.rb
Overview
Helper to define val= override after attribute declaration. Uses alias_method to save the generated setter, then overrides it.
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/uniword/properties/boolean_formatting.rb', line 23 def self.included(base) base.class_eval do # Save the generated val= method alias_method :__original_val_setter=, :val= if method_defined?(:val=) # Override val= with our custom logic define_method(:val=) do |v| @val = if v.nil? nil elsif v == false || v.to_s == "false" "false" elsif v == true || v.to_s == "true" nil else v end value_set_for(:val) if @val end end end |