You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a method that generates other methods. It's similar to attr_accessor in that it defines a getter and setter, but also generates a few others. simplified example:
But I'm at a loss as to how to type this. I could manually add def state_is_draft?: () -> bool and def state_is_published?: () -> bool to the Post class RBS, but in production, I could have 10 uses of enum with 3-5 possible values, and it defined up to 5 more methods for various purposes. That means I'd have to manually define up to 250 methods: enums * values * methods defined.
Does RBS support some way of defining methods generated once another method is called? Would need to combine some sort of block and loop function e.g.
moduleCustomEnummoduleClassMethodsdef enum: (Symbol column, Array[String] values) -> void do
values.each do |value|
def "#{column}_is_${value}?": () -> boolendendendend
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a method that generates other methods. It's similar to attr_accessor in that it defines a getter and setter, but also generates a few others. simplified example:
But I'm at a loss as to how to type this. I could manually add
def state_is_draft?: () -> bool
anddef state_is_published?: () -> bool
to the Post class RBS, but in production, I could have 10 uses of enum with 3-5 possible values, and it defined up to 5 more methods for various purposes. That means I'd have to manually define up to 250 methods:enums * values * methods
defined.Does RBS support some way of defining methods generated once another method is called? Would need to combine some sort of block and loop function e.g.
Beta Was this translation helpful? Give feedback.
All reactions