#ruby - 27 May 2017
« Back 1 day Forward 1 day »
[03:15:48] elomatreb: b0mbnet: It's not getting overriden, the local variable just takes precendence. You can still call the method if you use parentheses
[03:16:41] b0mbnet: but how do i know where this local variable takes precendence? which file and which line
[03:17:48] b0mbnet: i have a problem with grape, grape defined attr_reader for params, but it gets ovveride by local variable, and result is nil, i want to debug this
[03:19:46] elomatreb: All of those (provided you used a symbol for send) should call the method, not a local variable
[03:20:57] PorcoRex: b0mbnet, are you in search for where the local variable is defined, and not the method? I'm not sure that's possible, but I'd imagine that is one long method you're working with.
[03:21:32] elomatreb: I think a debugger might be able to trace where a variable was defined, but I haven't had to do that ever
[03:22:13] b0mbnet: yes, i have searched using ripgrep , but it is large result. i don't know where to start
[03:24:41] PorcoRex: b0mbnet, local variables should be encapsulated by a method. Do you know what this method is?
[03:29:43] b0mbnet: but in grape https://github.com/ruby-grape/grape/blob/master/lib/grape/endpoint.rb#L11
[03:30:40] elomatreb: It can only come from a scope above the block, is there anything above it that might set it?
[03:33:16] b0mbnet: desc method source code https://github.com/ruby-grape/grape/blob/220c345dff9602e431ac780abcb98dbb24293395/lib/grape/dsl/desc.rb#L40-L59
[03:34:28] stormbytes: whats wrong with my syntax? (ports = array, options=hash) if (options[:index] <= ports.length -1 )
[03:35:34] b0mbnet: i already tried using pry's watch function, but it is not working, beacause in this situation, local-variable is not changed, it is defined
[03:36:38] elomatreb: stormbytes: The error you're getting would help, doesn't look immediately wrong to me
[03:38:47] elomatreb: I think byebug (an actual debugger) may be able to do what you need, I don't know if it can trace variables directly but you can certainly step through your code until you see where it is defined
[03:40:09] PorcoRex: I hate to bring this again, but I'm not sure how this would work "desc 'create order' params do --- end post do --- end" without commas or anything.
[03:41:18] b0mbnet: i already tried, https://github.com/ruby-grape/grape/blob/521688848d916a851d79848d65f900157f6844b9/lib/grape/endpoint.rb#L256-L257, on line 256 params is ok, but when @block.call(self) params is nil, @block is the post block
[03:46:21] b0mbnet: beacause it is a attr_reader defined in here https://github.com/ruby-grape/grape/blob/521688848d916a851d79848d65f900157f6844b9/lib/grape/endpoint.rb#L11
[03:46:31] PorcoRex: You have to be careful, because both "params" and "post" aren't defining methods, but are method calls with passed blocks.
[03:46:40] elomatreb: Are you certain that the method does not return nil? I know that defined? is a bit of an oddity in Ruby, maybe it's just being quirky
[03:48:43] PorcoRex: b0mbnet, that's the problem, because outside post, "params" is a class method V1:Orders.
[03:50:10] elomatreb: That still wouldn't explain the local variable thing, which is actually pretty weird
[03:53:15] PorcoRex: b0mbnet, can you place a breakpoint inside "post" and perform "method(:params).owner"?
[03:58:56] b0mbnet: on https://github.com/ruby-grape/grape/blob/521688848d916a851d79848d65f900157f6844b9/lib/grape/endpoint.rb#L256, when i puts local_variables, it don't have params
[04:00:56] elomatreb: That's the weird thing, unless you're defining it in a scope above and before that it shouldn't bleed over from anywhere
[04:02:03] PorcoRex: There is no local variable both "params", inside and outside are different methods. Not variables.
[04:05:23] elomatreb: Yes, and they said it worked as intended when they explicitely called the method using self.params, params() or send
[04:07:12] PorcoRex: Ok, I think I've missed something then. I thought the confusion was because the call to "params" from withing "post" wasn't the one expected.
[04:07:56] b0mbnet: this is backtrace, https://gist.github.com/chen7897499/9a71f46d65061c03290052efaf79d57e
[04:15:08] PorcoRex: I'm no expert, but I think it doesn't work that way. Try calling params "xparams", for instance.
[04:17:25] PorcoRex: Rename the assignments to something else instead of params. Like "xparams = <something>"
[04:18:54] b0mbnet: assign? why? https://gist.github.com/chen7897499/9a71f46d65061c03290052efaf79d57e#file-gistfile1-txt-L14-L16, this lines is not run yet,
[04:19:24] b0mbnet: https://gist.github.com/chen7897499/9a71f46d65061c03290052efaf79d57e#file-gistfile1-txt-L12 on this line, params is nil
[04:21:46] elomatreb: defined? does some unexpected things sometimes, are you sure you're not being bitten by this behaviour?: https://eval.in/806112
[04:23:52] b0mbnet: https://gist.github.com/chen7897499/28414ba6fe3a57d8e5a087c92fabb74d#file-gistfile1-txt-L24 whole file
[04:24:46] elomatreb: Be aware that anything you execute in the pry can affect the code after it, it's like eval
[04:27:19] b0mbnet: beacause i already tried use local_variables, this one is safe, it can display all local variables on current
[04:35:03] b0mbnet: https://gist.github.com/chen7897499/9a71f46d65061c03290052efaf79d57e#file-gistfile1-txt and i don't understand where is generate_api_method being called
[04:36:23] b0mbnet: called here https://github.com/ruby-grape/grape/blob/521688848d916a851d79848d65f900157f6844b9/lib/grape/endpoint.rb#L102
[05:26:22] elomatreb: Well, unless you know that there is a difference between binary and unary minus it is kinda confusing
[11:21:04] codehotter: I'm a little bit out of my depth here, but if someone has time... How different would Ruby's AST format be from Mozilla's AST format?
[11:21:30] codehotter: Don't they have to fulfill mostly the same functions and so you'd expect them to look similar?
[15:14:25] Xandaros: Hi! I'm currently trying to understand this ruby script and I encountered a line I don't understand. Maybe someone here can help me. (I can't share the entire script, unfortunately). Line in question:
[16:00:39] ineb: Xandaros: calls a function named 'select' with 4 parameter. first parameter is an array with one entry. its only element is the global variable $my_socket. second parameter is nil, or null, nada. third parameter is identical to the first one and the last parameter is integer 1
[16:03:35] apeiros: Xandaros: note that `select` is most likely `Kernel#select` (can't tell without the surrounding code)
[16:04:14] Xandaros: It's alright, I can actually ignore that line. (I'm converting the script to python)
[16:04:27] apeiros: it is used to determine whether an IO is ready to be read from, or written to. the 1 means it times out after 1s
[16:08:23] Xandaros: Btw, how would I tell which module it's from? There is not import for "kernel" or anything. (Only socket and fcntl get impo... required)
[16:18:21] apeiros: Xandaros: but in general, toplevel methods (methods which have no receiver) are instance methods of the current scope's class
[16:18:44] apeiros: and all you have to do then is check that class and its ancestry (doc tools do that for you)
[16:18:59] Xandaros: I think to understand all this, I'd have to know more about how ruby actually works
[16:19:46] Xandaros: And unless my employer wants me to do something with ruby, I see no need to. I personally use Haskell for everything :P
[19:54:42] jwr: I'm not planning on doing ruby development, but i want to use ruby software (eg. jekyll) and have all the gems for each project separate so that various projects don't conflict with each other. do i want bundler, rbenv, or something else?
[20:16:39] jwr: hanmacl: thanks. upon reading the docs, the `cd some_project ; bundle exec some_cmd` workflow looks like exactly what i want.
[21:07:42] zenspider: jwr: I use ohmygems for most things. much simpler (it just sets up GEM_HOME + PATH)