meh` changed the topic of #opal to: http://opalrb.org - Ruby runtime and library on top of Javascript | 1.0.0 is near | This channel is logged at https://botbot.me/freenode/opal/
seamon has joined #opal
e_dub has joined #opal
brixen has quit [Excess Flood]
brixen has joined #opal
seamon has quit [Quit: Zzzzzzz]
e_dub has quit [Ping timeout: 250 seconds]
e_dub has joined #opal
fkchang has quit [Ping timeout: 260 seconds]
e_dub has quit [Quit: It's a hard knock life]
e_dub has joined #opal
femto has joined #opal
josh_cheek has joined #opal
femto has quit [Remote host closed the connection]
femto has joined #opal
<josh_cheek> Hi, I want to expose multiple examples where a user can try Ruby in a browser (e.g. a piece of information and an exercise to allow the reasder to quickly try the information out), but I don’t want the examples to be able to interfere with eachother. I looked at http://opalrb.org/try/# and I can run it once with a class and then later still access the class. (e.g. run the code, then delete the class definition and run again, it will work even
<josh_cheek> without the class there). This implies to me that the same opal object is passed into the function repeatedly. Normally I’d do my own research (aka read code), but I’m pretty noob at JS, so hoping someone can tell me whether I can make a separate runtime for each code example.
Lexun has joined #opal
<ryanstout> josh_cheek: Someone had done an opal-irb at one point, is that similar ot what your trying to do?
<josh_cheek> ryanstout: No, that’s a repl, I imagine there is a single context that is maintained throughout a dynamic session. I’m more thinking something like “this is how you use a block, (example + more in depth explanation), now your turn, solve this koan-like challenge: <ruby editor that is run against a test suite>”, but thing is that running tests one time should not interfere with the next.
<josh_cheek> ryanstout: ie I should be able to run from fresh-state each time.
<meh`> josh_cheek, your best bet would be to reload opal every time
<meh`> there's no good way to sandbox it
<meh`> unless well, you use an iframe :^)
<josh_cheek> meh`: If I make the assumption that the user does not write code that interacts with “Native”, can I get it sandboxed? Generated JS is a function that receives `$opal`, can I just isntantiate a new opal each time?
<meh`> josh_cheek, how do you mean?
<meh`> if you're evaluating code, there's no way to sandbox it
<meh`> in Ruby anything can change anything, even in the core classes
<josh_cheek> meh`: I see that as a pretty different use case, though. On http://opalrb.org/try/# I see the function receives `$opal`, My experiment leads me to believe it’s being called something like this (compensate with your imagination, pls): `opal = new Opal(); <a id=“run_code” onclick=“runOpal”>Run</a>; runOpal = function() { var userFunction = eval(getGeneratedCode); userFunction(opal); }` so I’m guessing I might be able to call it with
<josh_cheek> something like this: `generatedCode(new Opal());` where I give it a new Opal every time.
<meh`> josh_cheek, that's not the case
<meh`> $opal is a global thing
<josh_cheek> meh`: Or are you saying that even if I re-instantiated Opal, it would use the same classes?
<meh`> it can't be re-instantiated
<josh_cheek> Okay
<meh`> the only way is to remove the $opal variable
<meh`> and reload opal itself
<josh_cheek> I feel like this should be doable, but I probably don’t know enough JS to make the appropriate changes.
<meh`> josh_cheek, you should deep clone $opal
<meh`> and store it somewhere
<meh`> but it would be a pain to do consistently
<meh`> since it's a lot of nested stuff
femto_ has joined #opal
<josh_cheek> meh`: Yeah, I guess I mean that it seems like a better design that I could instantiate it and get a new VM (not sure if that’s the right word) which I could run code in. And unless there is a lot of code referencing a global object, it shouldn’t be too hard to update (and this could probably be found with a clever regex or parser). If I made this change, then as long as it’s not messing w/ the js outside of itself, state from one should n
<josh_cheek> affect state from another (ie they would both have their own Array class).
<meh`> josh_cheek, it's not that easy because of the runtime nature of Ruby semantics
<meh`> I'd say it's just not possible
<josh_cheek> I don’t understand
<josh_cheek> One Ruby process does not affect another Ruby process.
<meh`> josh_cheek, an OS process has nothing to do with JS :P
femto has quit [Ping timeout: 272 seconds]
<meh`> what the OS process does is copy the whole memory
<meh`> which is what you'd do by deep cloning the $opal object
<meh`> but even then, the code might be depending on local variables, other global variables and god knows what
<meh`> so it's just not possible to do
josh_cheek has quit [Ping timeout: 260 seconds]
Lexun has quit [Quit: Manjaro-KDE user leaving!]
Lexun has joined #opal
ryanstout has quit [Quit: ryanstout]
femto_ has quit [Remote host closed the connection]
femto has joined #opal
meh` has quit [Ping timeout: 260 seconds]
femto_ has joined #opal
femto has quit [Ping timeout: 260 seconds]
femto_ has quit [Ping timeout: 240 seconds]
femto has joined #opal
femto has quit [Remote host closed the connection]
femto has joined #opal
dimon_ has quit [Ping timeout: 250 seconds]
dimaursu16 has joined #opal
femto has quit [Remote host closed the connection]
femto has joined #opal
Lexun has quit [Ping timeout: 264 seconds]
femto has quit []
femto has joined #opal
femto has quit []
cantonic has quit [Quit: cantonic]
dimaursu16 has quit [Ping timeout: 250 seconds]
dimaursu16 has joined #opal
dimaursu16 has quit [Ping timeout: 240 seconds]
dimaursu16 has joined #opal
dimaursu16 has quit [Ping timeout: 240 seconds]
DrShoggoth has joined #opal
e_dub has quit [Quit: ZZZzzz…]
e_dub has joined #opal
Lexun has joined #opal
e_dub has quit [Client Quit]
meh` has joined #opal
e_dub has joined #opal
seamon has joined #opal
dimaursu16 has joined #opal
seamon has quit [Quit: Zzzzzzz]
Lexun has quit [Quit: Manjaro-KDE user leaving!]
seamon has joined #opal
e_dub has quit [Quit: ZZZzzz…]
seamon has quit [Quit: Zzzzzzz]
e_dub has joined #opal
meh`_ has joined #opal
e_dub has quit [Quit: It's a hard knock life]
meh` has quit [Ping timeout: 240 seconds]
e_dub has joined #opal
ryanstout has joined #opal
seamon has joined #opal
davispuh has joined #opal
e_dub has quit [Quit: ZZZzzz…]
seamon has quit [Quit: Zzzzzzz]
seamon has joined #opal
seamon has quit [Quit: Zzzzzzz]
seamon has joined #opal
e_dub has joined #opal
DrShoggoth has quit [Quit: Leaving]
seamon has quit [Quit: Zzzzzzz]