Activity Graph

Page 1 of 22 | Next »



[08:30:25] phaul: chances are that it only gives the same result because neither :var nor the thing var holds are in the hash, but they are not the same
[11:33:47] phaul: Quit: :wq
[11:35:27] phaul: has joined #RubyOnRails
[11:35:27] phaul: has joined #ruby-offtopic
[11:35:27] phaul: has joined #ruby
[14:05:49] phaul: Quit: :wq
[14:14:35] phaul: has joined #ruby-offtopic
[14:14:35] phaul: has joined #ruby
[14:14:36] phaul: has joined #RubyOnRails


[07:27:36] phaul: ri Kernel#exec
[07:27:39] phaul: &ri Kernel#exec
[07:31:23] phaul: altough echo in this example is probably built in
[07:34:08] phaul: I rarely use ruby as a shell script replacement so I almost never need to call external programs. Even when there is functionality I prefer a lib
[07:42:58] phaul: ruby -e '3.times { |n| puts %x("echo" "#{n}") }' # works
[11:21:18] phaul: Ping timeout: 272 seconds
[11:23:26] phaul: has joined #RubyOnRails
[11:23:26] phaul: has joined #ruby-offtopic
[11:23:26] phaul: has joined #ruby
[11:32:17] phaul: Ping timeout: 248 seconds
[11:32:45] phaul: has joined #RubyOnRails
[11:32:45] phaul: has joined #ruby-offtopic
[11:32:45] phaul: has joined #ruby


[16:02:18] phaul: I would check the PATH to make sure bundle is the bundle that was last installed. the command "which bundle" might help
[16:05:29] phaul: outher thing that you could try is updating the locate db, run slocate bundle and try each with --version and full path to see which one you want


[16:06:38] phaul: because {puts "x" } is not a parameter. it's a block. but that's normal value but special syntax
[16:07:06] phaul: and it's not counted in arity, has to be the last, and you can't put comma in front of it
[16:07:31] phaul: so this would work jkl(3,4) { puts "x" }
[16:07:58] phaul: arity is 2 and a block is additionally passed
[16:08:39] phaul: depends if you use the do end vs the braces syntax
[16:09:01] phaul: do end doesn't iirc
[16:46:19] phaul: you can pass a block to anything, they might just ignore it.
[16:46:40] phaul: &>> 1.+(2) { puts hello }
[16:46:58] phaul: passing a block to integer addition..


[07:02:03] phaul: I bet #concat tries to be more efficient by doing less string allocations. One has to benchmark to know for sure
[07:02:43] phaul: if there is difference it's going to be performance difference though
[10:05:39] phaul: &>> `ruby -h`


[09:27:52] phaul: a [op]= b is a syntactic sugar for a = a [op] b. there is no sugar for multiple ops prefixing the =
[09:28:54] phaul: Im not even sure what they would desugar to. a [op1][op2]= b maybe a = a op1 a op2 b? or maybe 2 bs an one a
[13:50:32] phaul: each_char returns what
[13:50:48] phaul: was the receiver if black was given
[13:52:07] phaul: &>> 'hello'.each_char { 'doesnt_matter_what_this_is' }
[13:53:46] phaul: you can chain a #map on it as it returns an Enumerator if no block was given
[13:58:30] phaul: &>> test = "test"; { |g| test.reverse.chomp(g) }
[21:12:18] phaul: &>> x = (rand < 0.5 ? Array : Hash);
[21:13:29] phaul: &>> class X < (rand < 0.5 ? Array : Hash); end;
[21:16:16] phaul: You can look at ObjectSpace.each_object it even takes a superclass (optionally)
[21:18:17] phaul: it's surprising sometimes how much is "just" code rather than special syntax


[07:04:26] phaul: has joined #RubyOnRails
[07:04:26] phaul: has joined #ruby-offtopic
[07:04:26] phaul: has joined #ruby


[13:41:10] phaul: Quit: :wq
[13:44:46] phaul: has joined #RubyOnRails
[13:44:46] phaul: has joined #ruby-offtopic
[13:44:46] phaul: has joined #ruby
[14:50:53] phaul: Ping timeout: 244 seconds
[15:02:20] phaul: has joined #RubyOnRails
[15:02:20] phaul: has joined #ruby-offtopic
[15:02:20] phaul: has joined #ruby
[15:07:06] phaul: Ping timeout: 272 seconds
[15:16:23] phaul: has joined #RubyOnRails
[15:16:23] phaul: has joined #ruby-offtopic
[15:16:23] phaul: has joined #ruby
[15:20:42] phaul: Ping timeout: 258 seconds
[15:27:23] phaul: has joined #ruby-offtopic
[15:27:23] phaul: has joined #ruby
[15:31:42] phaul: Ping timeout: 244 seconds


[18:04:15] phaul: show an example of a recursion that's clear and we can try explaining how this is the same/different. Or tell us a bit more about what's confusing about this example.
[18:05:32] phaul: general rule : it doesn't really matter what it does, what matters is that it gets down to base case, so it terminates..
[18:13:51] phaul: recursive expressions can go down to the base case and then bubble results using the return value of one level deeper in the summation of the one level up. That's basically how this works but Im not sure if my explanation helps..
[18:14:58] phaul: so it will reach lucas(1), and lucas(2) but then they will be added at lucas(3) and so on
[18:18:35] phaul: another way to look at this algorithm is: first you go all the way down in two binary trees where each node splits in two and then as subtrees with only two leafs are termintaing they become new leafs.
[18:19:34] phaul: if these explanations don't help then apologies, it's kind of hard to explain stuff over irc, and much easier too draw on a whiteboard


[12:27:58] phaul: it's a shame that the good old "expressiveness - succintness" and so on of ruby doesn't come up any more in these discussions.
[12:29:11] phaul: I think the more languages you know especially the more come from different paradigms the better off you are
[17:39:06] phaul: there is fetch, for hash and array from built ins. then you have safe navigation &. altrough with addressing [] it'sa bit inonvinient. blah&.[](index) looks silly but works
[17:39:59] phaul: inconvinient*
[17:41:12] phaul: so you can chain pr&.[]("interfaces")&.[](0)&. ...


[11:34:41] phaul: &25>> [[[1,2],[3,4]].map(&lambda do |a, b| a + b end), RUBY_VERSION]
[21:12:25] phaul: Quit: :wq
[21:13:45] phaul: has joined #RubyOnRails
[21:13:45] phaul: has joined #ruby-offtopic
[21:13:45] phaul: has joined #ruby


[06:55:17] phaul: Quit: :wq
[06:56:06] phaul: has joined #RubyOnRails
[06:56:06] phaul: has joined #ruby-offtopic
[06:56:06] phaul: has joined #ruby
[07:41:30] phaul: Quit: :wq
[07:43:10] phaul: has joined #RubyOnRails
[07:43:10] phaul: has joined #ruby-offtopic
[07:43:10] phaul: has joined #ruby
[12:05:52] phaul: sounds like a non deterministic issue that maybe is timing sensitive? Is there a possibility of race condition in you system?


[20:44:20] phaul:, bjpenn_
[20:57:17] phaul: There is some misunderstanting with the definition of Auth as well. The attr_reader :profile has 0 relation with the class instance variable @profile. It was probablymeant to be in an instance method
[20:58:26] phaul: &>>class X; @x = 13; attr_reader :x; end;
[21:02:44] phaul: you can put @vars at class level, but they don't mean instance vars for the instances of the class
[21:06:20] phaul: you are on the right track but no. .x is a method call and variables can't be accessed via method call
[21:06:39] phaul: it would be with X.instance_veriable_get(:@x)
[21:13:48] phaul: without line 18 it would give NoMethodError. With line 18 the NoMethodError disappears, but you get nil as nobody defined profile in any instances of Auth.
[21:17:24] phaul: bjpenn_: that change makes perfect sense
[21:18:10] phaul: no as leftylink and myself demonstrated with the bot the two codes are different
[21:19:09] phaul: now it's not class wide. now it's instance wide
[21:20:37] phaul: what you have to know is what self is in each context. That drives most of ruby semantics. Let me recommend you a ~1.5 hr video about the ruby object model :
[21:21:33] phaul: it's not the initialize. it's the fact that inside def; end you swith self to the instance
[21:21:50] phaul: from the class


[08:43:23] phaul: hi frojnd
[08:47:56] phaul: isn't this already json?
[22:15:53] phaul: Ping timeout: 245 seconds
[22:33:18] phaul: has joined #RubyOnRails
[22:33:18] phaul: has joined #ruby-offtopic
[22:33:18] phaul: has joined #ruby



[09:58:59] phaul: Quit: :wq
[13:46:42] phaul: has joined #RubyOnRails
[13:46:42] phaul: has joined #ruby-offtopic
[13:46:42] phaul: has joined #ruby


[08:13:37] phaul: AndreYuhai: probably you were setting a local variable. class X; attr_accessor :blah; def foo; blah=13; end; end; end here blah is a local variable. self.blah = 13 would set the instance variable
[08:13:54] phaul: or just @blah = 13
[08:19:12] phaul: looks good to me, do you have an issue with it?
[08:21:27] phaul: &>> old_relik [{"id"=>"3e8f493a-5662-4f10-9ac7-04fff7988009","data"=>87}].to_h { |h| [h["id"], {"data" => h["data"]}] }
[08:21:47] phaul: &>> [{"id"=>"3e8f493a-5662-4f10-9ac7-04fff7988009","data"=>87}].to_h { |h| [h["id"], {"data" => h["data"]}] } # old_relik
[08:22:10] phaul: it's a new thing
[08:22:14] phaul: 2.6 I think
[08:23:01] phaul: AndreYuhai: if you want the check to happen there as well you have to use the self.blah=(value) form
[08:23:31] phaul: difference is that the former is just an assignent to an instance variable, self.blah=() is a method call
[08:24:01] phaul: you can be liberal with the () and spaces around = though, so it's not evident that its a method call
[08:24:29] phaul: so self.blah = 13 is also method call
[08:25:30] phaul: no. it's just the default receiver.
[08:25:51] phaul: method() is usually equivalent to self.method()
[08:26:56] phaul: the method definition is a bit of exception..
[08:29:42] phaul: AndreYuhai: but does it work if you fix it the way I suggested? It should..
[08:31:03] phaul: I can recommend a pretty good explanation of the ruby object model from a video lecture, about 1.5 hr
[08:33:36] phaul: &>> class X; attr_reader :blah; def initialize(blah) ; self.blah = blah; end; end; def blah=(val); @blah = val * 2; end; end;; X.blah
[08:35:38] phaul: &>> class X; attr_reader :blah; def initialize(blah) ; self.blah=(blah); end; def blah=(val); @blah = val * 2; end; end; x =; x.blah
[08:35:44] phaul: there we go
[08:36:28] phaul: I just demonstrated it
[08:41:36] phaul: I explained it already, please read back .. │092331 phaul | difference is that ...
[08:43:15] phaul: I really recommend watching that video about the object model too, there you will learn that there is no class methods. Like in the matrix. There is no spoon :)
[09:44:31] phaul: &>> "hello 'world'".gsub("'", "\\\\'")


[21:58:16] phaul: match a regexp that is whitespace from start to end
[23:30:13] phaul: yes, kind of. override would happen in the child class, but given a single class, just use attr_reader, and just define def variable_name=(val) method
[23:32:40] phaul: &>> class X; attr_reader :blah; def blah=(val); @blah = 2 * val; end; end; x =; x.blah = 13; x.blah


[09:02:29] phaul: xco: in that example the return is not needed as there is nothing in the method that's after it
[09:02:49] phaul: so its just do_something! if something?
[09:04:47] phaul: with that the execution of return depends on the value of do_something!.
[09:06:20] phaul: but if doosomething is: def do_something! ; ...; nil; end then return will not be
[09:07:21] phaul: one has to know what do_something! does to see what this code does, which makes it worse than the original imho


[10:57:59] phaul: did you mean &&?
[10:59:15] phaul: & is the bitwise and operator. && is the logic and. "and" is the control flow and
[10:59:46] phaul: & typically used to and bitwise
[11:00:58] phaul: tap can be used for that, but also "and" is inherited from perl for the use case you described
[11:01:16] phaul: ppl usually don't like it because it might have surprising precedence
[11:02:10] phaul: well if do something is assign a variable then no.
[11:02:54] phaul:
[11:04:48] phaul: so what's there under the link is that a = true and false is (a = true) and false whereas a = true && false is a = (true && false)
[11:06:18] phaul: I have never written code in ruby with and myself. but my undesrtanding of the intention behind it is this flow control
[11:06:31] phaul: inherited from perl
[11:07:43] phaul: it's the dual of the perlism : do stuff or die
[11:09:11] phaul: leftylink: I agree with your suggestion, but I wanted to give a bit of background
[11:17:25] phaul: xco did this clear up things?
[11:18:21] phaul: that's actually different not the same program.
[11:19:05] phaul: that doesn't depend on the truthiness of the do_something whereas the versions with and do
[11:24:23] phaul: ok. so I think the way it's been done there is the best, because you don't care about the return value of do_something
[11:24:56] phaul: line 7-9 could be reduced to do_something_else if another_thing?
[21:06:39] phaul: the bot is a bit picky but ppl usually check whatever you paste on
[21:11:11] phaul: i did look at your pastebin but unfortunately I don't have a suggestion.
[21:12:53] phaul: ACTION said "ignore the bot for now" way too many times
[21:28:29] phaul: leftylink: maybe. it feels very specific to copy pastebin pastes (because that's the only thing rubybot cares about) to anywehere else. Imho that thing should just not be said any more. But I know the issues with this. rubybot is our legacy, and we are waiting for apeiros to return and decide how to move forward... And when rubydoc was born I didn't just put it into rubybot because its all in ruby2.3 I think
[21:29:34] phaul: and you dont really want to code ruby 2.3 in 2028/19 for fun
[21:30:36] phaul: I mean rubybot is 2.3


[14:37:57] phaul: gem install bundler
[14:38:47] phaul: assuming you have gem. and it installs to a place that is in the PATH


[11:34:23] phaul: &>> (s="accca").gsub(/a(.*)a/) { "{#{$1}}" }
[22:36:31] phaul: Quit: :wq
[22:38:35] phaul: has joined #ruby


[10:38:30] phaul: Quit: :wq
[10:48:04] phaul: has joined #ruby


[11:34:00] phaul: Quit: :wq
[12:03:22] phaul: has joined #ruby
[14:36:58] phaul: Nikhil_Singhal: what do you have so far?
[14:38:17] phaul: can you construct row n+1 from row n? Then it's just a recursion
[14:39:23] phaul: imagine you have pascal_triangle(n). can you append stuff to it to extend it to be pascal_triangle(n+1) ?
[14:42:54] phaul: def pascal_triangle(n) ; if n == 1; then [[1]] else prev=pascal_trianlge(n-1); prev + (extend_last_row(prev[-1]); end
[14:43:25] phaul: where extend_last_row just constructs the new row from the last row of the already existing smaller triangle
[15:44:04] phaul: you are checking palindromeness on a string that is 2 chars shorter ( removed first and last ) so it progresses towards the empty string
[15:46:00] phaul: well it just keeps calling palindrome to decide if the next shorter string is palindrome. At some point it calls itself wit the empty string, which I assume handled in this function as well
[15:47:15] phaul: one has to be careful about the edge cases especially ending with 1 character string at the end.


[11:04:41] phaul: &ri Hash#invert, depesz
[11:05:34] phaul: yeah, I was too quick :)
[14:29:10] phaul: &>> h = {}; h.merge!(a: 1, b: 2); h
[18:58:37] phaul: &fake Matz.quote
[18:59:05] phaul: that's all I can do for you happyhans :)
[19:01:43] phaul: just to clarify, "I" means the chat, where the core members yet to show up :P


[22:34:00] phaul: &>> [*'a' .. 'z'].join[-10..-1]
[22:35:14] phaul: where [*'a' .. 'z'].join is: "abc...z"
[23:28:58] phaul: many cats to way a skin


[10:00:58] phaul: &ri String#chomp!
[10:01:24] phaul: "or nil if no modifications were made"
[10:01:49] phaul: behaviour matches the documentation at least
[10:04:15] phaul: when using destructive methods, I usually don't even care about the return value. thing.chop! ; thing << ""
[10:04:55] phaul: communicates more clearly that these are all operations on thing
[18:18:06] phaul: &>> x = {[]}; x[0] << 'hi'; x[1] << 'comet23'; x
[18:18:27] phaul: &>> x = {[]}; x[0] << 'hi'; x[1] << 'comet23'; x
[18:20:51] phaul: not sure what it's called.. if all sub arrays are the same size maybe you can call it a matrix, given that it stores numbers


[23:02:28] phaul: Quit: :wq
[23:04:05] phaul: has joined #ruby
[23:04:06] phaul: has joined #RubyOnRails
[23:04:06] phaul: has joined #ruby-offtopic


[07:02:10] phaul: Net do you have a code example?
[07:03:09] phaul: I dont fully understand what is the aim here
[07:07:06] phaul: well.. good designs tend to have small classes with few methods which seems to be violated by the superclass
[07:08:09] phaul: if you don't own/want to touch the superclass, everything in the subclass will have a hacky feel to it
[07:08:51] phaul: xco
[07:11:16] phaul: Net: for methods that are not instance methods in the sense that they dont reference instance variables I would move them into a Module maybe nested in the class. for methods that touch instance variables, it's a bit tricky
[07:16:33] phaul: another thing to try is not to inherit, but delegate to an instance var of the superclass type
[07:17:53] phaul: that way you don't inherit the large interface, so your (subclass's) clients wont see any of it, so it stops the propagation of badness
[07:19:37] phaul: Im not big fan.
[21:04:38] phaul: I disagree. you can master each paradigm for their own sake. the mantra of this decade seems to be that fp is the real deal, and ppl start believing that it's something more that the other paradigm are building simply up to. Actually fp was first, and for a long time ppl were thinking the exact reverse. Imho the comparison or the merges of these paradigms are not that useful. Spending time in each is
[21:05:12] phaul: but each decade bring it own new set of buzzwords and craze
[21:06:47] phaul: for oo I recommend look into smalltalk
[21:07:01] phaul: or these days pharo
[21:07:09] phaul: which is smalltalk relly
[21:07:42] phaul: ruby is good too but way too much fluff to see the concepts
[21:09:08] phaul: beauty of pharo/smalltalk is that the language itself fits on a postcard
[21:10:20] phaul: it's a bit weird, unique in terms of environment
[21:11:39] phaul: it's a graphical integrated ui that you "boot into" and then you can start programm it
[21:12:48] phaul: ruby is nice but massively multi paradigm. you can do literally everything in any way in ruby


[16:24:40] phaul: I would think about making [url, ip] the key of a single layer hash..
[16:25:07] phaul: if they always go together...
[16:34:08] phaul: ngw, is there a good reason why you need two layers of hash? (going back to what I suggested). if you can make that move of removing the extra layer that would simplify the code everywhere
[16:35:58] phaul: yeah. a hash that maps pairs of page_url and ip to count
[16:36:56] phaul: or { [page_url, ip1] => 3 visits, [page_url ip2] => 1 visit }
[16:39:56] phaul: this has disadvantages too, for instance queries like is page_url hit cannot be easily queried any more. but querying with both url and ip is ok. depends on how you use the hash
[22:19:14] phaul: I agree when it's not in the middle of an on topic discussion. On low traffic, why not - as long as Ruby takes precedence.
[22:25:22] phaul: &fake Movies::BackToTheFuture.quote