Activity Graph

« Prev | Page 2 of 22 | Next »


[00:06:13] phaul: Ping timeout: 246 seconds
[00:28:46] phaul: has joined #RubyOnRails
[00:28:46] phaul: has joined #ruby-offtopic
[00:28:46] phaul: has joined #ruby


[22:06:52] phaul: Ping timeout: 246 seconds
[22:51:51] phaul: has joined #ruby-offtopic
[22:51:51] phaul: has joined #ruby
[22:51:52] phaul: has joined #RubyOnRails


[19:19:40] phaul: Quit: :wq
[19:20:33] phaul: has joined #RubyOnRails
[19:20:33] phaul: has joined #ruby-offtopic
[19:20:33] phaul: has joined #ruby
[20:02:32] phaul: it will not, the local variable will be defined but will be nil
[20:03:01] phaul: so it does more than not being there at all, which is pretty confusing
[20:03:35] phaul: &>> a = 13 if false; a
[20:07:03] phaul: hi comet23
[20:08:05] phaul: I would bet there isn't.
[20:13:30] phaul: it's probably O(n (log n)) depending on how hash lookup is implemented.
[20:14:06] phaul: you can do it in O(n) if you really want to by not doing hash lookup but indexing an array
[20:16:11] phaul: sorry I have to ask. Did you write this code or are you trying to understand it while you got it from somewhere else? You say how it will be implemented, but it already is...
[20:16:40] phaul: I can tell you what I think it does if that helps..
[20:20:49] phaul: 1.) creates a hash that maps chars of string 1. to the number of occurrences of the chars in string 1. 2.) does the same for string 2. walks the map of string 1, checking the for each count in string 1 if it matches the other map with that character. Ie checking if the strings have the same count of a given char.
[20:24:11] phaul: I think you can argue it's actually O(n)
[20:25:06] phaul: given the argument that the character set is limited, so there exists some constant that is greater than the stepps spent in hash lookup
[20:25:48] phaul: (in other words the hashes can only grow to a certain maxium size and after that they don't go anymore)
[20:27:39] phaul: O(n) means that there exists some c0,c1 constants that the number of steps required by your code is < c0 + c1 * n where n is the length of the strings
[20:28:22] phaul: it just means that if you increase your input sizes than the run time will increase with it propotionally
[20:28:49] phaul: as opposed to like exponentially
[20:29:18] phaul: O n just means n times bigger input -> roughly n times more time required
[20:31:21] phaul: comet23: there is a pretty unfortunate theorem, that proves that a computer program cannot decide of an other computer program in finite time if it finishes or not...
[20:31:46] phaul: called the halting problem


[23:27:32] phaul: you can walk ObjectSpace
[23:27:49] phaul: or call &list on the bot :P
[23:27:58] phaul: &list empty?
[23:29:41] phaul: walk ObjectSpace
[23:30:23] phaul: &>> ObjectSpace.each_object(Class).take(10)
[23:31:49] phaul: &>> ObjectSpace.each_object(Class).select { |klass| klass.instance_methods.include? :empty? }
[23:33:49] phaul: at the point when you run the code. Ruby is dynamic.. so this list can change as the program runs
[23:35:03] phaul: ObjectSpace always includes all objects in the system.
[23:35:21] phaul: classes/ modules and every other objects too.


[19:14:28] phaul: it's just a name of an argument. like id. except it's a block argument
[22:29:47] phaul: xco Array#any? {} Array#member? come to mind
[22:30:09] phaul: combined with %w(word word word)
[22:33:06] phaul: you have now :)
[22:35:18] phaul: no , follow jhass's example :) any? would require == check
[22:38:22] phaul: :( that's not what I expected tbh. I wanted Beatles and helpa
[22:39:00] phaul: there we go
[22:43:14] phaul: jhass: I think it's Radar's log bot


[15:42:42] phaul: it can take shape like
[15:45:14] phaul: not sure about being idiomatic there. it's debatable.


[00:00:36] phaul: "bar" and "baz" are strings. :bar and :baz are symbols
[00:00:42] phaul: different dta types for keys
[00:01:08] phaul: as far as accessing is concerend, the above two are the same
[00:01:51] phaul: meaning the hash doesn't care what data type it sees, it just works with it
[00:02:03] phaul: +- mri optimizations
[00:04:55] phaul: One caveat with symbols (which fit this purpose of being hash keys 99.9% of the time) is that they are never freed. So don't do it in a long lived process that allocated keys dynamically
[00:07:00] phaul: really, I didn't know. thank havenwood TIL
[00:08:09] phaul: ah. thanks for the info havenwood
[13:33:16] phaul: Kernel.print
[13:46:39] phaul: dont include MyHelper in MyModule. remove privateness on the helpermethod but make it module_function or class side method. Call it by explicitly calling it on the module. : MyHelper.helpermethod
[13:48:05] phaul: this way things that explicitly qualifiy helpermethod with Myhelper. can use it. You can make MyHelper a private constant so it's not visible ooutside of MyModule
[13:51:07] phaul: &ri private_constant, for making MyHelper private in MyModule
[14:09:29] phaul: &>> table = [1, 2] ; table.methods
[14:12:30] phaul: I'm not sure what test is in your code, probably a method?
[14:13:32] phaul: I don't think so. what's test in your code? and why do you have it there? why not just table =
[14:19:05] phaul: ryouba: I did not see the last message :)
[14:22:54] phaul: hm. I don't know how to fix that. private_constant only prevents you from using MyModule::Myhelper, but if MyHelper is already in sight due to the include MyModule then it's not hidden
[14:23:41] phaul: but you have to be explicit at least about including it in MyClass, so it's not that bad
[14:24:31] phaul: private_constant is a not that old invention, originally ruby wasn't designed with private modules / private classes in mind
[14:25:52] phaul: although it becomes a bit phylosophical because everything is always callable via send anyways
[14:30:03] phaul: well, including and using class side methods on the module are different , they are not interchangable
[14:30:22] phaul: although module_function adds support for both
[14:31:13] phaul: havenwood: I was surprised that private_constants leak out to things that include the module that defined them.
[14:47:22] phaul: ryouba: it's function as in "functionality". Meaning a bunch of methods defined on the instance side and on the class side of the module. Not function as in functional programming.
[14:47:45] phaul: &ri module_function
[14:48:24] phaul: although the docs there also mix the terms so idk
[14:50:26] phaul: anyways it defines multiple methods
[14:52:20] phaul: except it also calls methods function
[14:56:54] phaul: idk. maybe it refers to the pair of defined methods as the "function" as a single entity.
[15:42:46] phaul: brool:
[15:43:49] phaul: it's both now


[16:06:31] phaul: fetch can take a block but you still have to set it
[16:07:45] phaul: foo.fetch(bar) {|k| foo[k] = baz(...) }
[16:10:08] phaul: &>> foo = {a: 1, b: 2}; v = foo.fetch(:c) {|k| foo[k] = 3 }; [v, foo]
[16:11:22] phaul: &>> foo = {a: 1, b: 2}; v = foo.fetch(:a) {|k| foo[k] = 42 }; [v, foo]
[16:14:16] phaul: although it's different from ||= I think on falsey values. but I think fetch is correct and ||= is a bug.
[16:16:01] phaul: &>> foo = {a: false } ; v = foo[:a] ||= 2; [v, foo]
[16:16:38] phaul: unless this is what you want, Net . note the key :a was in the hash and we still updated it with ||=
[17:24:04] phaul: !hangman ruby
[17:24:23] phaul: DeBot: !hangman ruby
[17:24:42] phaul: DeBot: ae
[17:24:57] phaul: DeBot: st
[17:27:37] phaul: &list OpenSSL::ASN1::%
[17:28:12] phaul: &list OpenSSL::ASN1::O%
[17:28:47] phaul: DeBot: bjc


[13:59:54] phaul: loveyouthreethou: self.something
[14:00:36] phaul: it's a method techniqually not a variable.
[14:02:47] phaul: struct is the same, it's methods there too. just pair of a setter + getter
[14:03:35] phaul: it's no issue, but the implicit self invocation can mislead the parser to take the token as local variable
[14:03:48] phaul: but with explicit self it's always a method call
[14:07:22] phaul: yes loveyouthreethou


[01:26:46] phaul: the latter just references a local variable foo or method call on self foo
[01:27:17] phaul: syntactically it's valid
[01:27:37] phaul: probably undefined variable or method call error though
[01:28:40] phaul: :foo is just a Symbol constant that's passed to the method attr_reader. no special syntax is involved..
[01:30:17] phaul: no. :foo is a symbol and it's just any other object with no special behavioour, it's like 5, 'blah' , 3.14 etc
[01:30:46] phaul: it can be thought of as a constant string
[01:31:33] phaul: attr_reader is a method that defines a getter method dynamically based on the symbol it got
[01:32:05] phaul: and the getter method will use the symbol name to access the instance variable too.


[11:56:08] phaul: why don't you use throw/catch instead? that was designed for control flow, raise rescue was designed for error handling
[11:59:18] phaul: you go out all nested block with throw, then once you are out you redo?
[22:39:53] phaul: 1 test passed.
[22:39:58] phaul: 0 failures.


[16:42:07] phaul: they just changed name, now they are haxx0r
[19:54:06] phaul: as a side note predictable temp file names are security hole. and $$ is predictable
[19:55:05] phaul: depends on your needs, for a single user desktop and one user script it doesn't matter.


[00:00:50] phaul: one is for lexical nesting of modules diregarding any relation of objects the other is all about relating objects disregarding layout of code.
[00:02:51] phaul: module A ; module B; end ; end. means A and B has no relation to each other whasoever apart from B is lexically layed out in the code of A
[13:57:14] phaul: " where it would automatically pass the two arguments " - map doesn't want to pass 2 arguments, it wants to pass 1. Do you mean inject/reduce ?
[14:03:06] phaul: &>> foo = -> (a, b) { a + b }; [1,2,3].reduce(&foo)
[14:03:26] phaul: syndikate: ^ if that's what you want
[21:03:06] phaul: Quit: :wq
[21:04:46] phaul: has joined #RubyOnRails
[21:04:46] phaul: has joined #ruby-offtopic
[21:04:46] phaul: has joined #ruby


[23:57:23] phaul: &ri constants
[23:57:42] phaul: &ri Module#contants
[23:57:46] phaul: &ri Module.contants
[23:57:59] phaul: I give up.
[23:59:07] phaul: it's not really opposite. they are really unrelated concepts.


[16:53:02] phaul: &>> [:debit, :debit, :credit].each_cons(2).none?([:credit, :debit])
[16:53:16] phaul: &>> [:debit, :debit, :credit, :debit].each_cons(2).none?([:credit, :debit])
[16:55:33] phaul: but how do you sort? /me confused
[16:55:49] phaul: &>> :debit <=> :credit
[16:55:58] phaul: rly? ok. cool
[16:56:17] phaul: well, I like your solution :)
[16:56:43] phaul: I didn't think of comparing symbols..
[16:58:21] phaul: one thing is that mine, and havenwood's are O(n) you are probably O n (log n) but really doesn't matter unless you have thousands of entries
[17:19:18] phaul: Exuma: there are more things it can do for you, docs :


[11:27:51] phaul: no, it's in the instances. Not in the class
[11:28:27] phaul: last token on line 11 refers to class method / local variable
[11:31:11] phaul: right. but don't let the code drive your design. Consider what it actually belongs to
[11:31:36] phaul: and implement it that way


[23:16:07] phaul: you can nest modules, but you have to resolve nesting with ::
[23:16:26] phaul: ok you found the way
[23:17:47] phaul: you could do :: on the method too, so Foo::Bar::blah works, but Dont. This is the acceted way.
[23:18:38] phaul: modules and methods are different, it's fine to separate them differently - as far as dissonance is concerned
[23:21:04] phaul: calling a method on a receiver, and resolving a constant in module nesting are fundamentally different things
[23:22:51] phaul: upper case methods work too. but..
[23:40:16] phaul: yes. or even better def self.method
[23:40:35] phaul: as self is ModuleName in the Module context
[23:43:27] phaul: ah. it's true what I said but didn't really make sense, so the short answer is yes you were right with that symm-


[08:10:34] phaul: al2o3-cr: it does only 1 at a time, the second bit is either a nick or stuff to append, in this case it's stuff to append
[10:38:28] phaul: 3.times { return 'file' if File.exist?('file'); sleep (4) } ; return 'file not found'
[10:40:35] phaul: no, return needs it to be in a method


[12:52:33] phaul: &>> require 'time';Time.iso8601(
[12:54:59] phaul: what is it?
[12:57:09] phaul: &ri Time#iso8601
[12:57:57] phaul: oh. that explains it :D
[12:59:28] phaul: so you got 2019-05-07 amount of digits :)


[23:37:23] phaul: &>> a = [1,2]; b = a; a << 3; b # there can be many variables pointing to the same object
[23:43:05] phaul: &>> a =, [1]) ; a[0] << 1; a
[23:43:17] phaul: it can be tricky


[16:23:18] phaul: "This method allows you to treat the files supplied on the command line as a single file consisting of the concatenation of each named file. "
[16:25:09] phaul: I don't know. I think I agree with you now
[16:26:11] phaul: displaying the filename once per file: yeah if it works the way it does it would only print the first file
[16:27:41] phaul: yeah the documentation certeainly suggest that
[16:36:03] phaul:
[16:36:44] phaul: there is explicit tests for line numbers
[18:00:05] phaul: depends. There are two main approaches afaict , the repository pattern (prefered by most) vs the active record pattern
[18:00:37] phaul: what you are describing is closer to active record pattern
[18:00:42] phaul: sorry, the other one
[18:00:48] phaul: repository pattern
[18:01:42] phaul: having classes per "models" (db tables) whose class methods relate to all entries and instance methods relate to rows
[18:03:09] phaul: the connection can be kept persistent in the app for either solutions
[18:07:14] phaul: one way: inside Singleton app object, that's created from top level "main"
[18:07:47] phaul: then you just pass that around. It's a disguised bunch of global vars
[18:08:26] phaul: still you are explicit about passing it, so a bit better than $connection
[18:12:01] phaul: that's almsot the same.
[18:14:01] phaul: difference being wehter every place can call $db.close and mess with things, or you can have large chunks of unrelated libraries and codes that simply can't see the db connection


[18:57:40] phaul: Quit: :wq
[18:59:37] phaul: has joined #RubyOnRails
[18:59:37] phaul: has joined #ruby-offtopic
[18:59:37] phaul: has joined #ruby


[11:14:27] phaul: Quit: :wq
[11:17:27] phaul: has joined #RubyOnRails
[11:17:27] phaul: has joined #ruby-offtopic
[11:17:27] phaul: has joined #ruby
[21:09:27] phaul: oldie but goddie I guess
[21:11:51] phaul: are you a programmer, who tries to lear ruby or are you someone who wants to learn programming using ruby?
[21:47:17] phaul: remember that what's printed is a representation of "the same thing" via to_s, or inspect. not the string that you have in memory
[21:48:07] phaul: msg rubydoc &>> '\"'
[21:51:51] phaul: but that's because in " which it prints \\ is \ and \" is just ". if it was printing ' it would be '\\"' but it choses to print "
[21:53:31] phaul: but it's the same string, different way of printing the same value
[22:03:27] phaul: renlolo: in '' world \\ is just a \. \" is \" . Meaning of \ depends on what follows. It's either 2 or 1 byte
[22:04:06] phaul: same in " world but different rules
[22:05:18] phaul: &>> '\\'.bytesize
[22:11:10] phaul: as inside the String
[22:20:22] phaul: most of use that thecnique for this. Keep sticking in \ until it works. It's correct but so confusing to undertsand...
[22:21:20] phaul: I mean ruby is correct, but noone can work out how many \ they need :)
[23:22:57] phaul: not that it's different anywhere else that has similar semantics for ' and "...


[19:15:31] phaul: &>> [{a: 1}] * 3
[19:16:42] phaul: but with this kind of stuff you always have to be careful of what's deep cloned and whats the same object multiple times
[19:21:34] phaul: no idea fishcooker sorry. Have you tried following the instructions in the error message?
[19:25:22] phaul: &>> &>> x = [{a:1}] * 3; x[0][:b] = 2; x # ule
[19:25:30] phaul: &>> x = [{a:1}] * 3; x[0][:b] = 2; x # ule
[19:30:32] phaul: &>> x = { {a:1} }; x[0][:b] = 2; x
[19:31:38] phaul: so just know the difference of these ^ two. as it can be really hard to debug if an object is referenced from multiple places of a program.
[19:32:21] phaul: multiple data structures rather
[19:37:09] phaul: so in [a] * n you get an array of one *single* object n times, whereas { a } gives an array of n objects each of wich initially equal to a. that's the main gotcha with this
[19:47:47] phaul: hopefully someone with RVM knowledge comes along...
[20:01:47] phaul: zenspider: rvm. we need you ! :)
[21:18:16] phaul: how about
[21:19:04] phaul: ah. that checks condition on the mapped values
[21:20:34] phaul: p.find(&:condition)&.then(&:transform_value) ?
[21:21:50] phaul: &>> [1,2,3].find(&:even?)&.then { |x| x + 17 }


[19:27:44] phaul: it's the singletonclass of object pointed by a really, but it just says String. Same with prepended modules
[19:33:52] phaul: a is not visible inside init as def is lexical scope for locals
[19:34:18] phaul: you can use blocks with define_method, if you want to break that lexical scope
[19:36:14] phaul: &>> a = 'cat' ; define_method(:init) { |obj| a.define_method(:upcase) { 'xx' + obj } }
[19:38:23] phaul: actually you would need a.define_singleton_method
[19:41:00] phaul: &>> a = 'cat' ; define_method(:init) { |obj| a.define_singleton_method(:upcase) { 'xx' + obj } }; init('!!!'); a.upcase
[19:42:19] phaul: yeah, my last example is 1:1 applicable, just rename the variables
[19:43:27] phaul: str.define_singleton_method(:test) { @foobar } # it doesn't even have to be @, it can be just local var
[19:44:39] phaul: blocks let outer scope local variables through. or in other word they are closures
[19:49:07] phaul: &>> a = 'cat' ; define_method(:init) { |obj| a.define_singleton_method(:upcase) { super + obj } }; init('!!!'); a.upcase
[19:49:17] phaul: &>> a = 'cat' ; define_method(:init) { |obj| a.define_singleton_method(:upcase) { super() + obj } }; init('!!!'); a.upcase
[19:54:29] phaul: yeah just pass arguments explicitly ie super()
[19:58:56] phaul: no. super is a keyword that is calling the parent with matching name, so super("aaa")