These are chat archives for opal/opal

21st
Oct 2016
Mitch VanDuyn
@catmando
Oct 21 2016 14:37
I am just dreaming here... I was sure that Method#parameters was implemented, but i tried it just now (for putting some pry like debug tools) and I can't find it...
just looking to get the arg names of a method....
Mitch VanDuyn
@catmando
Oct 21 2016 14:54
hah! I guess I had implemented it myself in the cannonbol gem:
  class Proc

    def parameters
      /.*function[^(]*\(([^)]*)\)/.match(`#{self}.toString()`)[1].split(",").collect { |param| [:req, param.strip.to_sym]}
    end

  end
any big technical reason why this cannot be implemented? If so I know somebody that might like to try add it properly...
Elia Schito
@elia
Oct 21 2016 15:31
@catmando There was some WIP from @iliabylich for that but don't remember how far it went, you sure arity is enabled in the opal config?
Mitch VanDuyn
@catmando
Oct 21 2016 15:32
arity shows up... not sure how would I enable "arity"
what else can I enable?
i don't know about this enable business...
Jamie Gaskins
@jgaskins
Oct 21 2016 15:38
@elia You can find out the arity of any method or proc without enabling anything, right? I thought the config flag was just for runtime arity checking.
Mitch VanDuyn
@catmando
Oct 21 2016 15:39
@jgaskins that is what I am seeing (i.e. i got the arity, but no checking)
Jamie Gaskins
@jgaskins
Oct 21 2016 15:39
:+1:
Mitch VanDuyn
@catmando
Oct 21 2016 15:40
another question: What is the best way to deal with in coming params that might (or might now be native objects)... Is there a way to somehow convert things so that they will always act like ruby objects?
is that what Native[...] does?
Elia Schito
@elia
Oct 21 2016 15:44
@catmando it's Native(object)
Mitch VanDuyn
@catmando
Oct 21 2016 15:44
great...
Elia Schito
@elia
Oct 21 2016 15:46
@catmando @jgaskins parameters is filled only with arity check enabled, compare opal -A -cEO -e '-> a,*b { foo }' with opal -cEO -e '-> a,*b { foo }'
only with -A you see TMP_1.$$parameters = [['req', 'a'], ['rest', 'b']]
Mitch VanDuyn
@catmando
Oct 21 2016 15:47
and how does this work:
puts "this is a native object #{Native(`{a: 12}`)}"
# prints -> this is a native object [object, object]
# but
puts "this is a native object #{Native(`{a: 12}`).inspect}"
# prints -> this is a native object
# and so does
puts "this is a native object #{Native(`{a: 12}`).to_s}"
nice!
I have no clue how you flip that switch? say in a rails environment for example
Elia Schito
@elia
Oct 21 2016 15:49
Should be done in an initializer that configures opal via Opal::Config https://github.com/opal/opal/blob/0-10-stable/lib/opal/config.rb#L7-L16
each of those can be set directly on Config: Opal::Config.arity_check_enabled = true
Mitch VanDuyn
@catmando
Oct 21 2016 15:53
fyi we should enable it on try/opal
Mitch VanDuyn
@catmando
Oct 21 2016 15:59
fyi active-support inflections dies with that switch... will do a PR shortly :-)
Elia Schito
@elia
Oct 21 2016 16:25
@catmando looking forward to it!
Mitch VanDuyn
@catmando
Oct 21 2016 16:32
there ya go
perhaps all tests should be run with that arity switch on?
Adam Jahn
@ajjahn
Oct 21 2016 16:39
@elia @catmando While you're looking at the active support inflector, I've got a PR to fix the pluralize behavior lingering out there: opal/opal-activesupport#13
Elia Schito
@elia
Oct 21 2016 17:16
@ajjahn sorry, I need to fix the travis setup and let travis become green
Adam Jahn
@ajjahn
Oct 21 2016 18:27
@elia No problem.