<misfo>
i.e. something analogous to having a `def self.some_method() end` at the top-level
<jfredett>
misfo: you can sometimes use a module to avoid that, though I'm not sure what your goal is
<jfredett>
if you have a method on a module like module Foo; def run(&block) ; instance_eval(&block); end ; end
<jfredett>
err -- self.run
<jfredett>
then you can include in Foo your module
<jfredett>
and if you want to run code, you run it inside of a block passed to Foo.run
<jfredett>
technically refinements can also be sort of kind of used for this, but I don't recommend it (the semantics are super complicated)
NemesisD has joined #rom-rb
<NemesisD>
hey guys. i'm trying to submit a patch to grape to get it working with the virtus 1.0 betas. i'm having it coerce an array of bools. i'm wondering if i'm using virtus wrong
<NemesisD>
it looks like the coercer of the attribute is Coercible::Coercer::Array, its method is :to_array,
<misfo>
@jfredett i wasn't being clear. Using `def self.some_method() end` at the top-level of a file defines the method only on the main object and avoids polluting all objects with your method: https://gist.github.com/misfo/6796883 I was looking a way to add all the methods in a module to the main object w/o polluting all object
<jfredett>
misfo: ah... hmm
<jfredett>
I don't think there's a way to do that -- all objects walk up the tree and will find stuff in Object
<jfredett>
actually, there is a way, it's just toast and you shouldn't use it -- namely Refinements -- iirc the scoping rules would prevent that pollution
<jfredett>
why do you need to do it that way?
cored has quit [Ping timeout: 240 seconds]
<NemesisD>
before the code was using Virtus::Attribute.build(:a, [Virtus::Attribute::Boolean]), which doesn't work anymore, not sure if those are equivalent
skade has quit [Quit: Computer has gone to sleep.]
cored has joined #rom-rb
cored has joined #rom-rb
<NemesisD>
looks like it works if i use TrueClass instead of Virtus::Attribute::Boolean
<NemesisD>
and Axiom::Types::Boolean
misfo has quit [Ping timeout: 250 seconds]
skade has joined #rom-rb
snusnu has quit [Quit: Leaving.]
misfo has joined #rom-rb
<misfo>
jfredett: you asked about the use case - if a script is using a bunch of constants that are deeply nested, it would be convenient not to have to type the namespace over an over again
<jfredett>
misfo: yah, there's no convenient way to get around it -- though in limited-use scripts I have done dirty things like NS = Common::Chunk::Of::Namespace, so I can just do NS::Whatever
<misfo>
yeah, that's the best work around i've seen
<misfo>
seems weird, though, that there's a way to define singleton methods on main but there's not a way to add all methods from a module as singleton methods
<misfo>
because that's what `extend` does inside a class definition, in my understanding
<jfredett>
well, sortof
<jfredett>
the effect is 'equivalent' -- but really it alters the Ancestor Heirarchy
<jfredett>
include adds <YourModule> to the class's ancestors, extend adds it to the eigenclasses' ancestors
<misfo>
right, so shouldn't `extend Some::Module` at the top-level of a file add that module to `main`'s eigenclass and therefor make any constants in that module available at the top-level?
<jfredett>
main is just Object
<jfredett>
the constants should be available at the top level
<jfredett>
but they'll also be in Object
<jfredett>
because main is object
<jfredett>
because ruby is weird
<misfo>
agreed
skade has quit [Quit: Computer has gone to sleep.]