sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    [Plugin] AttributeInspector 1.1.1 – 2014-05-08

    已排程 已置頂 已鎖定 已移動 Plugins
    45 貼文 10 Posters 3.8k 瀏覽 10 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • Dan RathbunD 離線
      Dan Rathbun
      最後由 編輯

      BTW... you can currently use the triple equal method with Length class, so this will work:
      true === length_value || false === length_value

      I'm not here much anymore.

      1 條回覆 最後回覆 回覆 引用 0
      • Dan RathbunD 離線
        Dan Rathbun
        最後由 編輯

        @aerilius said:

        Or shouln't ruby have a "Boolean" super class of which TrueClass and FalseClass are subclasses?
        type = (value.is_a?(TrueClass) || value.is_a?(FalseClass)) ? "Boolean" : value.class.to_s

        I always wondered why not ?

        One thing I have done in the past is create a boolean?() query method for Object (or something else like Comparable.
        Now this is frowned upon, and I never released it, just suggested, or had it in my test scripts.

        
        def boolean?()
          is_a?(TrueClass) || is_a?(FalseClass)
        end unless method(;boolean?)
        

        AND / OR, ... create a Boolean mixin module, and then mix it into only TrueClass and FalseClass. The mixin module may not actually need any additional functionality, at all ?

        Then the kind_of? (alias is_a?,) methods will return the appropriate true or false using a Boolean class argument, for any, and ALL objects.
        The === will also work for all objects, which makes case statements work:
        Boolean === value


        Whichever one (or both,) ya'll want, would need to be adopted as an API extension, by the community. (And we'd need to convince the Trimble team to add it.)

        I'm not here much anymore.

        1 條回覆 最後回覆 回覆 引用 0
        • tt_suT 離線
          tt_su
          最後由 編輯

          The Length class is a bit of a special case. It's trying to be a sub-class of Float - but the Ruby API doesn't really let you do this. So there's some hackery in the background to make it work. I'll file an issue to see if we can avoid the argument error.

          1 條回覆 最後回覆 回覆 引用 0
          • Dan RathbunD 離線
            Dan Rathbun
            最後由 編輯

            Thanks TT.

            Just returning false would be preferable, instead of raising an ArgumentError (when really TypeError occurs.)

            I'm not here much anymore.

            1 條回覆 最後回覆 回覆 引用 0
            • tt_suT 離線
              tt_su
              最後由 編輯

              Yea, there's a few annoying inconsistency where the correct error isn't raised.

              1 條回覆 最後回覆 回覆 引用 0
              • 1
              • 2
              • 3
              • 3 / 3
              • 第一個貼文
                最後的貼文
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement