queirozfcom / rachinations

Other
2 stars 0 forks source link

Quero passar funções como label para Edges na DSL #74

Closed xexeo closed 9 years ago

queirozfcom commented 9 years ago

Pode passar já. Qualquer coisa que é ruby válido pode entrar ali. Eu marquei esse ticket como inválido mas se não for isso (expliquei no e-email) que o senhor tinha em mente é só falar.

xexeo commented 9 years ago

Não funcionou como eu queria. Eu quero que a cada chamada o Edge chame a função, não que chame na primeira vez. Por isso tentei lambda { Random.rand(10) } E recebo esse erro (pois Proc não tem times) Em algum lugar você dá label.times. Com inteiros funciona, mas com blocks precisa ser label.call.times. Tentei definir times para Proc mas não deu certo. Talvez desse certo definir call para Fixnum como return self. Mas é muito feio mexer em Proc ou FixNum.

Então imaginei transformar o getter de label para executar dentro dele se for um lambda.

Então, tirei o label do attr_reader e fiz isso:

def label if @label.is_a?(Proc) return @label.call end @label end

E funcionou como queria. Mas talvez você ache uma implementação melhor.

C:\Ruby21-x64\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/Users/Geraldo/RubymineProjects/untitled1/lop C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rachinations-0.0.5/lib/rachinations/domain/nodes/source.rb:134:in block in push_any!': undefined methodtimes' for #Proc:0x00000002f9a720 (NoMethodError) ===== INITIAL STATE ===== from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rachinations-0.0.5/lib/rachinations/domain/nodes/source.rb:126:in `each'

from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rachinations-0.0.5/lib/rachinations/domain/nodes/source.rb:126:in `push_any!'

from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rachinations-0.0.5/lib/rachinations/domain/nodes/source.rb:66:in `trigger!'

Source 's1' from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rachinations-0.0.5/lib/rachinations/domain/diagrams/diagram.rb:156:in `block in run_first_round!'

Pool 'p1': Empty

from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rachinations-0.0.5/lib/rachinations/domain/diagrams/diagram.rb:156:in `each'

from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rachinations-0.0.5/lib/rachinations/domain/diagrams/diagram.rb:156:in `run_first_round!'

======= ROUND 1 ======= from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rachinations-0.0.5/lib/rachinations/domain/diagrams/diagram.rb:115:in `run_while!'

from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rachinations-0.0.5/lib/rachinations/domain/diagrams/diagram.rb:89:in `run!'
from C:/Users/Geraldo/RubymineProjects/untitled1/lop:11:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'

Process finished with exit code 1

queirozfcom commented 9 years ago

Tudo bem professor, eu vou incluir um teste com isso e quando estiver passando e o senhor der o OK eu marco esse ticket como resolvido.