« Back to channel list

#ruby - 17 October 2018

Forward 1 day »
[02:37:21] helpa: has joined #ruby
[02:48:34] zxq2: zenspider, i would like to single-step code to better understand what it's doing
[02:51:06] arekushi: has joined #ruby
[02:58:59] orbyt_: has joined #ruby
[03:04:10] zenspider: zxq2: that's not your problem. that's your proposed solution.
[03:09:01] braincrash: has joined #ruby
[03:11:50] bmurt: has joined #ruby
[03:27:29] darkhanb: has joined #ruby
[03:32:22] orbyt_: has joined #ruby
[03:48:57] _kupo: has joined #ruby
[03:51:33] dellavg_: has joined #ruby
[04:06:03] rivalomega: has joined #ruby
[04:10:07] asphyxia: has joined #ruby
[04:15:56] lxsameer: has joined #ruby
[04:24:38] MyMind: has joined #ruby
[04:32:35] MoritaShinobu: has joined #ruby
[04:43:32] tdy: has joined #ruby
[04:46:06] ramfjord: has joined #ruby
[04:47:27] s2013: has joined #ruby
[04:50:16] asphyxia: has joined #ruby
[04:53:01] sawdog: has joined #ruby
[04:56:38] skwurl: has joined #ruby
[04:57:52] skwurl: hi, how can i randomly assign an array into 3 different variables.
[04:58:12] skwurl: im trying something like :
[04:58:47] skwurl: a, b, c = array.sample
[04:59:15] Radar: randomly assign the elements from the array into those 3 variables?
[04:59:22] havenwood: skwurl: a, b, c = array.sample 3
[04:59:23] skwurl: a, b, c = array.sample(3)
[04:59:41] havenwood: skwurl: note, those won't be repeated elements
[04:59:43] Radar: havenwood wins again
[04:59:47] skwurl: drka drrr
[05:01:35] havenwood: for repeated, one way is: a, b, c = Array.new(3) { array.sample }
[05:03:09] havenwood: (though it's nicer not to do parallel assignment there)
[05:05:46] reber: has joined #ruby
[05:21:11] skwurl: parallel assignment is not random though right?
[05:25:48] MoritaShinobu: has joined #ruby
[05:39:00] LenPayne: has joined #ruby
[05:41:42] whysthatso: has joined #ruby
[05:42:48] havenwood: skwurl: right, it's ordered
[05:43:41] skwurl: anybody using weechat?
[05:45:18] skwurl: havenwood: i need it to be random
[05:46:02] havenwood: skwurl: You want to assign three variables to random, distinct array elements?
[05:47:10] havenwood: skwurl: sample(3) is random order, which is maintained when assigned in parallel
[05:49:29] havenwood: >> [*0..10].sample(3)
[05:49:32] skwurl: is the above an example of that?
[05:49:35] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[05:49:42] havenwood: #=> [9, 5, 2]
[05:49:48] havenwood: #=> [5, 10, 3]
[05:49:54] havenwood: #=> [1, 10, 6]
[05:50:10] havenwood: skwurl: ^ it'll always be three elements of the array, never the same one twice
[05:52:25] skwurl: oh yeah that works great.
[05:52:53] skwurl: heres how i've applied it...
[05:53:02] skwurl: d4, d8, d12 = ['Warrior','Wizard','Explorer',].sample(3)
[05:53:18] skwurl: its for a tabletop rpg 'Dungeon Squad'
[05:54:02] skwurl: heres another question
[05:54:03] havenwood: skwurl: array.shuffle
[05:54:44] havenwood: skwurl: %w[Warrior Wizard Explorer].shuffle
[05:55:13] skwurl: even briefer
[05:55:50] havenwood: skwurl: %i[d4 d8 d12].zip(%w[Warrior Wizard Explorer].shuffle).to_h
[05:56:07] havenwood: #=> {:d4=>"Explorer", :d8=>"Warrior", :d12=>"Wizard"}
[05:56:26] skwurl: whaa...???
[05:56:51] skwurl: i dont like that one
[05:57:18] skwurl: .to_h is ?
[05:57:24] havenwood: skwurl: to Hash
[05:57:53] skwurl: %i , %w ?
[05:58:15] havenwood: skwurl: shorthand for Array of Symbols and Array of Strings
[05:58:47] skwurl: okay thats not to bad
[06:01:11] Hanmac: has joined #ruby
[06:01:13] skwurl: here's another question. howcome when i puts the output of a class its not in the same order as the methods within it?
[06:02:25] mahlon: has joined #ruby
[06:02:38] havenwood: skwurl: Another way to write it:
[06:02:39] havenwood: %w[Warrior Wizard Explorer].shuffle.each_with_object({}).with_index { |(role, result), index| result[:"d#{index * 4}"] = role }
[06:02:50] havenwood: #=> {:d0=>"Warrior", :d4=>"Wizard", :d8=>"Explorer"}
[06:03:09] havenwood: oops, bad maths
[06:03:17] havenwood: %w[Warrior Wizard Explorer].shuffle.each_with_object({}).with_index(1) { |(role, result), index| result[:"d#{index * 4}"] = role }
[06:03:21] havenwood: #=> {:d4=>"Warrior", :d8=>"Explorer", :d12=>"Wizard"}
[06:03:53] havenwood: skwurl: Show an example of what you mean?
[06:03:55] skwurl: damn thats kind of long though. if i can
[06:03:57] skwurl: d4, d8, d12 = ['Warrior','Wizard','Explorer',].shuffle
[06:03:58] roshanavand: has joined #ruby
[06:04:18] havenwood: skwurl: I was just being silly to avoid having to type 4, 8 and 12
[06:05:10] havenwood: skwurl: yes, that's a fine way
[06:05:17] skwurl: ok one sec
[06:05:25] skwurl: new_character = Character.new
[06:05:36] skwurl: puts new_character
[06:06:06] skwurl: or codeshare ....
[06:06:32] skwurl: https://codeshare.io/5ejdL4
[06:08:37] venmx: has joined #ruby
[06:10:19] skwurl: havenwood: i have alot of questions. like also why do i bot need to def initialize in this or no attr-reader is not necessary
[06:11:41] za1b1tsu: has joined #ruby
[06:12:16] havenwood: skwurl: By initializing, you can memoize the skills so #skills returns the same ones every time for a character.
[06:13:09] havenwood: skwurl: If you don't need any internal state (anything remembered) then you can use a module instead of a class.
[06:13:26] havenwood: skwurl: Do characters have skills when they're created?
[06:13:27] Nicmavr: has joined #ruby
[06:13:53] havenwood: skwurl: Can a name be changed?
[06:14:40] skwurl: the names are sampled from a textfile
[06:15:32] havenwood: skwurl: Try setting @instance_variables for the name and skills in an initialize method.
[06:15:59] skwurl: heres a look at the character sheet
[06:16:39] skwurl: http://cdn.obsidianportal.com/assets/102004/CDS_CharacterSheetExample.png
[06:16:45] mahlon: has joined #ruby
[06:21:53] MyMind: has joined #ruby
[06:25:10] havenwood: skwurl: for ideas: https://gist.github.com/havenwood/d36a1ee469aa19e1e12b69136cb00d90
[06:25:55] havenwood: skwurl: With that code ^, how would you implement #name and #skills methods?
[06:26:13] skwurl: id you see my codeshare?
[06:26:25] skwurl: di you see my codeshare?
[06:26:33] skwurl: https://codeshare.io/5ejdL4
[06:27:10] havenwood: skwurl: Yes. I tried to show an example with initializing state, but didn't implement #name and #skills like your example.
[06:27:44] havenwood: skwurl: If you added those methods, which printed the same output as your example (#to_s as well) - you'd have something working that preserved state between method calls.
[06:27:46] MoritaShinobu: has joined #ruby
[06:28:05] havenwood: skwurl: The instance variables are what stick around between method calls.
[06:28:14] havenwood: skwurl: @name and @skills
[06:29:10] havenwood: skwurl: Adding to the bottom of your codeshare...
[06:33:10] aupadhye: has joined #ruby
[06:34:53] Puffball: has joined #ruby
[06:36:31] havenwood: skwurl: Let me know if any of my comments in the codeshare don't make sense or if you'd like me to expound.
[06:39:04] skwurl: makes sense. theres a couple things ive seen before but havent learned about yet. Your approach really minimizes redundancies
[06:41:29] ramfjord: has joined #ruby
[06:42:20] skwurl: im finding there are alot of options to do things.
[06:56:31] marz_d`ghostman: has joined #ruby
[06:56:47] marz_d`ghostman: Is it possible to stub a gem I am using in my script?
[06:56:52] marz_d`ghostman: for rspec testing?
[06:57:16] baweaver: Yes, but why?
[07:00:29] yokel: has joined #ruby
[07:01:11] marz_d`ghostman: baweaver: How? I'm currently using double, doesn't seem to be working though. I'm trying to test that my conditionals are working if the gem succeeds/fails.
[07:02:05] baweaver: allow(something).to receive(:method).with(:arguments).and_return(something_else)
[07:08:38] lunarkitty7: has joined #ruby
[07:11:21] clemens3: has joined #ruby
[07:15:37] whysthatso: has joined #ruby
[07:25:46] dogweather: has joined #ruby
[07:29:53] throwntall: has joined #ruby
[07:35:40] aufi: has joined #ruby
[07:39:19] tuor: has joined #ruby
[07:40:22] clemens3_: has joined #ruby
[07:46:19] marz_d`ghostman: baweaver: I'll try that, thanks.
[07:46:42] lyr: has left #ruby: ("The Lounge - https://thelounge.github.io")
[07:50:38] armyriad: has joined #ruby
[07:54:26] marz_d`ghostman: baweaver: Can't seem to make it work though. Am I missing something? https://gist.github.com/marzdgzmn/8ba0bc2ccb70295b6d105f24afba96bd
[07:58:05] GodFather: has joined #ruby
[07:58:21] baweaver: That's why you let us know earlier on what your actual code is.
[07:58:31] baweaver: You need to stub out the yield to the block as well.
[07:59:20] baweaver: allow(something).to receive(x).with(y).and_yield(z)
[08:03:17] BTRE: has joined #ruby
[08:04:09] marz_d`ghostman: hmmm, tried allow(Marz::Rsync).to receive(:run).with(any_args).and_yield(result), but output doesn't seem to be stubbed
[08:04:30] marz_d`ghostman: oh my bad, it is
[08:13:41] wildermind: has joined #ruby
[08:15:13] lxsameer: has joined #ruby
[08:15:35] alem0lars: has joined #ruby
[08:16:37] mikecmpbll: has joined #ruby
[08:24:25] marz_d`ghostman: Does Rspec.describe run any methods prior to the test? I have a puts method inside my class and it seems to be invoked before the tests
[08:25:53] jp: has joined #ruby
[08:30:49] tbuehlmann: marz_d`ghostman: it's plain inside the class? then it's executed when the class is loaded
[08:32:32] venmx: has joined #ruby
[08:33:59] marz_d`ghostman: tbuehlmann: I have this method: https://gist.github.com/marzdgzmn/8ba0bc2ccb70295b6d105f24afba96bd and the puts gets invoked before any tests. Does that mean that the gem(Marz::Rsync) method gets invoked too?
[08:35:06] tbuehlmann: uh, no, that method shouldn't be called by rspec before your examples
[08:38:50] marz_d`ghostman: cause puts result.output is invoked apparently
[08:42:05] ramfjord: has joined #ruby
[08:46:21] nowhere_man: has joined #ruby
[08:46:50] jetchisel: has joined #ruby
[08:50:55] ReporterMan: has joined #ruby
[08:53:29] zxq2: rspec is like broken english
[08:55:06] zxq2: don't know why it attempts to mimic a natural language
[08:55:54] zxq2: readability isn't gained
[08:58:58] phaul: has joined #ruby
[09:00:03] zxq2: the little readability that's gained is bought with an awkward syntax, which makes writing a pain
[09:02:45] Spitfire: has joined #ruby
[09:03:03] phaul: rspec isn't for everyone. some love it. some don't. I do.
[09:05:17] phaul: but I agree that not fully understanding whats a method call there, what expect gives back, why matchers are chainable, or what runs when, makes it really a false promise
[09:05:54] phaul: dangerous too. You can easily write something that runs and passes but dooesn't test what you wanted
[09:07:18] phaul: but.., if you know how to use it, it becomes productive. at least for me
[09:20:22] Reporter_: has joined #ruby
[09:24:41] johnny56: has joined #ruby
[09:27:16] ikbenhet: has joined #ruby
[09:32:15] SanguineAnomaly: has joined #ruby
[09:42:07] bijan_: has joined #ruby
[09:44:27] arekushi: has joined #ruby
[09:51:51] za1b1tsu: has joined #ruby
[10:10:34] xfbs: has joined #ruby
[10:10:47] mister_solo: has joined #ruby
[10:14:24] mister_solo: has joined #ruby
[10:19:03] lxsameer: has joined #ruby
[10:23:22] vonfry: has joined #ruby
[10:26:23] za1b1tsu: has joined #ruby
[10:32:10] apeiros_: has joined #ruby
[10:34:17] aufi: has joined #ruby
[10:37:56] lxsameer: has joined #ruby
[10:42:21] ramfjord: has joined #ruby
[10:46:41] apeiros_: has joined #ruby
[10:47:24] apparition: has joined #ruby
[10:52:12] kurko_: has joined #ruby
[10:56:00] apeiros: has joined #ruby
[11:07:48] nowhere_man: has joined #ruby
[11:15:04] lxsameer: has joined #ruby
[11:15:12] koensw: has joined #ruby
[11:15:52] DTZUZO_: has joined #ruby
[11:18:09] mister_solo: has joined #ruby
[11:19:42] ikbenhet: has joined #ruby
[11:24:54] cd: has joined #ruby
[11:44:49] rivalomega: has joined #ruby
[11:45:14] lxsameer: has joined #ruby
[11:52:41] crankharder: has joined #ruby
[11:59:07] marmotini_: has joined #ruby
[11:59:11] Bish: since when is 2007-01-01 not valid 8601?
[11:59:21] Bish: >> Time.iso8601("2007-01-01")
[11:59:26] ruby[bot]: Bish: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[12:00:12] za1b1tsu: has joined #ruby
[12:00:23] Bish: >> require 'time';Time.iso8601("2007-01-01")
[12:00:29] ruby[bot]: Bish: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[12:01:12] marmotini: has joined #ruby
[12:03:21] nertzy: has joined #ruby
[12:03:40] Bish: ArgumentError: invalid date: "2018-10-17"
[12:03:49] Bish: while this is taken from the wikipedia page of iso8601
[12:06:09] bhaak: >> require 'time'; Time.iso8601("2007-01-01T12:34:56")
[12:06:15] ruby[bot]: bhaak: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[12:06:33] bhaak: looks like the bot is broken?
[12:07:11] bhaak: >> require 'date'; puts Date.iso8601("2007-01-01")
[12:07:17] ruby[bot]: bhaak: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[12:07:17] Pupeno_: has joined #ruby
[12:07:21] bhaak: na, broken
[12:07:34] bhaak: but the explanation is in the documentation of iso8601
[12:07:40] crankharder: has joined #ruby
[12:08:00] bhaak: "alias for xmlschema" and under xmlschema: "Parses date as a dateTime defined by the XML Schema and converts it to a Time object. The format is a restricted version of the format defined by ISO 8601."
[12:08:05] bhaak: _restricted_
[12:08:20] apeiros: bhaak: Date.iso8601 if you don't have a time part
[12:08:43] apeiros: and the above error with the bot is sadly http://eval.in being broken
[12:10:09] apeiros: personally I'd consider it correct if Time.iso8601("2007-01-01") would be treated as 2007-01-01T00:00:00 in local time. apparently ruby sees that differently.
[12:11:59] Bish: apeiros: but i don't know beforehand if i have a date part
[12:12:00] bhaak: puts then you would get a Time object and not a Date object.
[12:12:28] kapil____: has joined #ruby
[12:12:46] bhaak: s/puts/but
[12:12:51] bhaak: too much ruby
[12:12:58] Bish: ruby - where method named after a standard, don't get you the standard
[12:13:20] Bish: and i remember this being differently
[12:13:22] mister_solo: has joined #ruby
[12:13:26] Bish: different*
[12:13:50] bhaak: you might remember the parse method and not iso8601?
[12:14:12] apeiros: Bish: uh, yeah, don't tell me it's difficult for you to test that :-p
[12:17:44] Bish: bhaak: no, that code is super old
[12:18:13] Bish: apeiros: well, there will always be testcases that slip through
[12:18:28] Bish: like.. not testing a method that is named after an iso
[12:18:37] Fusl: has joined #ruby
[12:18:54] Bish: maybe i should test if nil.nil?
[12:19:16] nowhereman: has joined #ruby
[12:22:10] bhaak: I just tested it for 1.8.7, doesn't work either
[12:23:05] bhaak: looking at the source code, the relevant method has been last changed in 2014. the regexp matches the input string even only in 2008
[12:24:56] apeiros: Bish: you certainly should. also test 1 < 2 and "string".is_a?(String) for good measure
[12:25:13] apeiros: ACTION afk
[12:33:04] lxsameer: has joined #ruby
[12:42:44] ramfjord: has joined #ruby
[12:55:50] GodFather: has joined #ruby
[12:56:13] nertzy: has joined #ruby
[12:57:53] apeiros_: has joined #ruby
[12:58:31] throwntall: has joined #ruby
[13:02:06] bsrd: has joined #ruby
[13:02:09] whysthatso: has left #ruby: ()
[13:07:09] whysthatso: has joined #ruby
[13:07:39] knight33: has joined #ruby
[13:07:50] bsrd: Hey I've a puma server running a grape API. We've just had a down and unresponsive period because our logger died. I'm thinking about just offloading to a new thread whenever we log something and continue without calling join or value, so reponses are made regardless of whether the log is alive or not. Has anyone experience with that?
[13:08:02] crankharder: has joined #ruby
[13:09:13] whysthatso: has joined #ruby
[13:09:50] aupadhye: has joined #ruby
[13:10:22] deathwishdave: has joined #ruby
[13:10:42] ikbenhet: has joined #ruby
[13:17:28] rivalomega: has joined #ruby
[13:19:40] apeiros_: has joined #ruby
[13:22:06] JusticeFries: has joined #ruby
[13:28:21] darix: bsrd: log to something like a message bus and feed your real log destination from there
[13:36:40] lxsameer: has joined #ruby
[13:37:43] crankhar1er: has joined #ruby
[13:42:39] Xiti: has joined #ruby
[13:44:24] mixfix41: has joined #ruby
[13:51:14] Xiti: has joined #ruby
[14:00:12] bsrd: darix: Thanks! sucker_punch gem seems to be the solution I want.
[14:00:47] jetchisel: has joined #ruby
[14:02:23] vondruch: has joined #ruby
[14:03:21] darix: just feeding into sidekiq would be one way yes
[14:05:57] ramfjord: has joined #ruby
[14:06:01] discopatrick: has joined #ruby
[14:06:50] phaul: has joined #ruby
[14:12:08] rivalomega: has joined #ruby
[14:13:54] venmx: has joined #ruby
[14:16:32] nowhere_man: has joined #ruby
[14:16:43] Rapture: has joined #ruby
[14:21:16] knight33: has joined #ruby
[14:22:42] Dbugger: has joined #ruby
[14:29:41] MoritaShinobu: has joined #ruby
[14:32:07] dbugger_: has joined #ruby
[14:33:44] marmotini_: has joined #ruby
[14:34:20] kurko__: has joined #ruby
[14:34:25] crankharder: has joined #ruby
[14:39:52] planigan_: has joined #ruby
[14:45:57] elomatreb_: has joined #ruby
[14:46:55] ablackack_: has joined #ruby
[14:47:55] kurko_: has joined #ruby