Dart equivalent of Ruby's instance_eval -
ruby has neat method called instance_eval
allows evaluating block of code in context of specific instance. great because 1 can use same block of code in different contexts , different results based on how context defines methods. there equivalent in dart? in other words can take method class , attach , execute on instance in class or define method letting user pass in code corresponding method. know limited form of possible emulate subclassing.
it seems there no possibility of doing in dart. use several approaches, depending on needs:
creating function context argument of function:
somefunction (context, arg1, arg2) { ... }
using mixins: https://www.dartlang.org/articles/mixins/
- using generics: https://www.dartlang.org/articles/optional-types/#generics
Comments
Post a Comment