« Back to channel list

#ruby - 28 December 2018

« Back 1 day Forward 1 day »
[00:02:11] elphe: has joined #ruby
[00:11:51] tdy: has joined #ruby
[00:15:34] cschneid: has joined #ruby
[00:20:06] cthu|: weird. I don't know why I'm getting this error
[00:20:27] cthu|: I do temp_event = {} and then:
[00:20:45] cthu|: temp_event.key?("screen_name") ? screen_name = temp_event["screen_name"] : screen_name = ""
[00:21:10] cthu|: it says my temp_event is undefined
[00:21:23] cthu|: nil class doesn't have the .key? method
[00:22:03] phaul: &>> temp_event = {} ; temp_event.key?("screen_name") ? screen_name = temp_event["screen_name"] : screen_name = ""
[00:22:04] rubydoc: # => "" (https://carc.in/#/r/5v7o)
[00:22:47] cthu|: https://i.imgur.com/eWLGx6I.png
[00:24:45] phaul: cthu|: without understanding that what;s happening in that case, Hash#fetch would do what you are doing in a more elegant way
[00:25:35] phaul: screen_name = temp_event.fetch("screen_name", "")
[00:26:01] al2o3-cr: or screen_name = temp_event['screen_name'] || ''
[00:26:07] cthu|: thank you
[00:26:09] cthu|: but still
[00:26:17] cthu|: I want to know what's wrong with my object
[00:26:55] al2o3-cr: but fetch is more elegant.
[00:27:02] cthu|: I will use fetch
[00:27:18] cthu|: we can do it like in JS?
[00:27:25] cthu|: I was sure we couldn't
[00:28:03] cthu|: &>> qwe = asd["asd"] || "foo"
[00:28:04] rubydoc: # => undefined local variable or method `asd' for main:Object (NameError) (https://carc.in/#/r/5v7p)
[00:28:08] cthu|: yeah, we can't
[00:28:21] al2o3-cr: sure, you can.
[00:28:34] cschneid: has joined #ruby
[00:28:37] kapil____: has joined #ruby
[00:29:17] al2o3-cr: &>> h = {}; h[:foo] || 'nah'
[00:29:18] rubydoc: # => "nah" (https://carc.in/#/r/5v7q)
[00:30:02] al2o3-cr: &>> h = {foo: 42}; h[:foo] || 'nah'
[00:30:03] rubydoc: # => 42 (https://carc.in/#/r/5v7r)
[00:30:06] cthu|: I'm not familiar with :
[00:30:17] cthu|: no idea what it does
[00:30:22] cthu|: phaul, https://paste.ofcode.org/35MJgEypkzBg9m8PVHB2LUf
[00:30:48] cthu|: throws me NoMethodError: undefined method `key?' for nil:NilClass
[00:30:58] cthu|: on line 8
[00:33:30] cthu|: al2o3-cr, I think it works cuz you use symbolic links. I don't use them. I just do => cuz it feels more fair.
[00:34:40] tdy: has joined #ruby
[00:36:30] cthu|: same error with fetch
[00:36:49] cthu|: I think I know
[00:36:59] cthu|: it's cuz blocks don't have access to this
[00:37:08] cthu|: which is stupid af
[00:37:13] cthu|: I think I had this issue before
[00:40:06] orbyt_: has joined #ruby
[00:40:15] cthu|: I wonder if blocks that use do end can use the context.
[00:40:23] JoeA2552: has joined #ruby
[00:41:12] Guest44017: has joined #ruby
[00:43:50] cthu|: now I have to have an ugly temp_event = temp_event || {} in each iteration because of the fact that I don't have the context. that's sad. Can I add arbitrary arguments to blocks? Like f.each_line { |line, temp_event={}|
[00:53:10] cthu|: I don't have match?
[00:53:20] cthu|: no string.match? no regex.match?
[00:53:54] ByronJohnson: has joined #ruby
[00:55:11] cthu|: okay, I'm gonna use the ugliest ===
[01:02:25] cschneid: has joined #ruby
[01:28:04] JoeA2552: has joined #ruby
[01:30:17] D4rK51D3: has joined #ruby
[01:32:31] D4rK51D3: hi everybody
[01:32:36] r29v: has joined #ruby
[01:34:15] havenwood: D4rK51D3: hi
[01:34:28] D4rK51D3: i just have a simple question, i dont know if maybe somebody can help, i just want to make a facebook autoposter in ruby, to work maybe in localhost as a webpage, or maybe just as a executable, is ruby the right language to do this?
[01:35:19] D4rK51D3: autoposter (MULTI-poster, post a single post but in many different groups at the same time with a simple click
[01:35:54] D4rK51D3: is this possible in ruby? is it the right language for this? anybody ? :|
[01:36:08] JoeA2552: has joined #ruby
[01:36:30] cthu|: why Ruby?
[01:36:38] cthu|: it makes sense to use JS in this case
[01:36:44] cthu|: locally in browser
[01:36:51] cthu|: unless heavy backend is involved
[01:38:34] cthu|: also, D4rK51D3 I believe there are many solutions that can be easily employed. Generally, it's either you hack and make it hard for FB to know that it's automated or you use its API. In the latter case you don't care about the language. In the former, however, you wanna use JS
[01:39:03] sarink: has joined #ruby
[01:39:15] D4rK51D3: i dont know, ive just enrolled in a ruby course and i think it is much easier than python
[01:39:57] cthu|: oh, if you're a student, you probably don't wanna start messing with a task like this. Unless you feel confident with APIs
[01:39:59] D4rK51D3: but i really dont have an idea
[01:40:56] cthu|: also I wouldn't say Python is more complex or easier than Ruby. They're different, but have approximately the same level
[01:41:41] D4rK51D3: so you mean in ruby this task would be much harder? or more difficult?
[01:42:12] havenwood: D4rK51D3: Pretty much any modern language is perfectly fine for making an HTTP API client. Ruby is a fine choice.
[01:43:21] JoeA2552: has joined #ruby
[01:43:36] D4rK51D3: i definitely would use facebook API
[01:45:05] D4rK51D3: i need to pull lot of info from facebook so i will need the API, nothing about spamming, facebook has rules about multiposting, since you respect those rules no problem
[01:45:10] havenwood: D4rK51D3: Maybe check out the Koala gem: https://github.com/arsduo/koala#readme
[01:46:03] jcalla: has joined #ruby
[01:50:18] esrse: has joined #ruby
[01:50:26] D4rK51D3: Koala is a Facebook library for Ruby, supporting the Graph API (including the batch requests and photo uploads), the Marketing API, the Atlas API, realtime updates, test users, and OAuth validation
[01:51:20] davidw: has joined #ruby
[01:53:28] connermcd: has joined #ruby
[01:56:09] D4rK51D3: so my idea wouold be to make a "website" hosted in localhost, and from there manage my multipostings, receibe feedback from the facebook API, how about that?
[01:58:33] JoeA2552: has joined #ruby
[01:59:52] D4rK51D3: is that a good/bad idea?, what is your expert opinion?
[02:07:46] hays: is there anything like the pickaxe book that is up to date
[02:10:21] D4rK51D3: has left #ruby: ("Leaving")
[02:10:53] JoeA2552: has joined #ruby
[02:12:46] comet23: rate my clean code out of 10
[02:12:48] comet23: https://repl.it/repls/TrueMotherlyRegister
[02:18:15] lambarena: has joined #ruby
[02:23:42] b6b: has joined #ruby
[02:29:47] tdy: has joined #ruby
[02:31:27] FrankD: has joined #ruby
[02:47:18] hutch: has joined #ruby
[02:48:48] orbyt_: has joined #ruby
[02:53:43] tdy: has joined #ruby
[03:05:09] kapil____: has joined #ruby
[03:07:14] orbyt_: has joined #ruby
[03:12:10] Milos: has joined #ruby
[03:16:48] hays: should i read the manning book?
[03:17:03] hays: seems to be the most recent that is actually about ruby
[03:17:52] hutch: has joined #ruby
[03:20:30] elphe: has joined #ruby
[03:21:07] comet23: manning is a terrible publisher
[03:21:14] comet23: you wanna learn ruby?
[03:21:22] comet23: look up app academy online it's free
[03:21:38] comet23: full full stack developer course at your own pace
[03:30:40] hays: looking for a deeper understanding of the language
[03:30:50] hays: dont really care about being a full stack dev
[03:31:16] hays: industry seems to be moving away from this anyway
[03:32:52] hays: articles online about ruby are of pretty inconsistent quality
[03:34:11] davidw: has joined #ruby
[03:43:53] hutch: has joined #ruby
[03:46:51] ogres: has joined #ruby
[03:48:51] baweaver: hays: What're you trying to learn?
[03:49:38] hays: well, ive been spending some time reading about the ruby object model
[03:49:51] hays: watched a dave thomas video
[03:49:56] baweaver: Want to see some Ruby black magic? :D
[03:50:07] hays: but really would like to just get a good overview
[03:50:08] baweaver: https://medium.com/@baweaver/mf-abusing-rubys-operator-precedence-ccf3f071bad8
[04:03:15] hutch: has joined #ruby
[04:08:59] braincrash: has joined #ruby
[04:09:50] sgen_: has joined #ruby
[04:12:33] MasterAsia: has joined #ruby
[04:12:59] darkhanb: has joined #ruby
[04:13:57] cschneid: has joined #ruby
[04:18:51] hays: i see you have a new article out :)
[04:51:44] ansraliant: has joined #ruby
[04:59:08] KeyJoo: has joined #ruby
[05:19:11] sauvin: has joined #ruby
[05:22:10] davidw_: has joined #ruby
[05:40:54] sarink: has joined #ruby
[05:51:30] jtdowney: has joined #ruby
[05:54:11] _whitelogger: has joined #ruby
[06:20:19] laaron: has joined #ruby
[06:25:17] JoeA2552: has joined #ruby
[06:26:00] cthu|: has joined #ruby
[06:30:11] _whitelogger: has joined #ruby
[06:38:15] rippa: has joined #ruby
[06:48:10] _whitelogger: has joined #ruby
[06:51:25] za1b1tsu: has joined #ruby
[06:57:11] _whitelogger: has joined #ruby
[07:01:15] laaron-: has joined #ruby
[07:04:25] jthomas1: has joined #ruby
[07:15:09] _whitelogger: has joined #ruby
[07:18:29] dellavg_: has joined #ruby
[07:21:09] _whitelogger: has joined #ruby
[07:22:42] JoeA2552: has joined #ruby
[07:29:49] cschneid: has joined #ruby
[07:39:22] LightStalker: has joined #ruby
[07:41:52] neuraload: has joined #ruby
[07:56:02] JoeA2552: has joined #ruby
[07:58:22] roshanavand: has joined #ruby
[07:59:55] cnsvc: has joined #ruby
[08:01:46] laaron: has joined #ruby
[08:07:58] cthu|: has joined #ruby
[08:21:10] _whitelogger: has joined #ruby
[08:33:40] Mike11: has joined #ruby
[08:38:56] BH23: has joined #ruby
[08:42:18] conta: has joined #ruby
[08:50:25] tiff: has joined #ruby
[08:53:07] reber: has joined #ruby
[09:09:15] elphe: has joined #ruby
[09:12:19] neuraload: has joined #ruby
[09:16:36] gix: has joined #ruby
[09:35:52] kapil____: has joined #ruby
[09:36:35] lxsameer: has joined #ruby
[09:46:12] Nicmavr: has joined #ruby
[09:48:27] marz_d`ghostman: has joined #ruby
[09:49:02] marz_d`ghostman: I've created a /config/initializers/production.rb & test.rb . . . to initialize things. However, how do I select which one should be included when I run it in production and test?
[09:55:52] mikecmpbll: has joined #ruby
[10:03:27] laaron: has joined #ruby
[10:06:28] roshanavand: has joined #ruby
[10:32:18] powerbit: has joined #ruby
[10:32:44] elphe: has joined #ruby
[10:35:56] powerbit: has joined #ruby
[10:40:27] powerbit: has joined #ruby
[10:40:40] elphe: has joined #ruby
[10:43:42] roshanavand: has joined #ruby
[10:48:28] keden: has joined #ruby
[10:51:12] ur5us: has joined #ruby
[10:56:59] quipa: has joined #ruby
[10:59:49] quipa: has joined #ruby
[11:01:30] laaron-: has joined #ruby
[11:06:56] elphe: has joined #ruby
[11:25:44] yxhuvud: has joined #ruby
[11:26:59] KeyJoo: has joined #ruby
[11:29:49] phaul: has joined #ruby
[11:29:55] rubydoc: has joined #ruby
[11:51:41] elphe: has joined #ruby
[12:03:50] laaron: has joined #ruby
[12:06:46] bobthebutcher: has joined #ruby
[12:19:00] cschneid: has joined #ruby
[12:35:19] elphe: has joined #ruby
[12:44:05] patteh_: has joined #ruby
[12:52:23] hays: i am thinking i should just read the pickaxe book
[12:52:38] hays: and then just read the changelogs of ruby from 1.9
[12:54:42] mostlybadfly: has joined #ruby
[13:02:51] al2o3-cr: hays: look @ /topic for book references.
[13:08:08] lucasb: has joined #ruby
[13:08:20] neuraload: has joined #ruby
[13:10:37] AJA4350: has joined #ruby
[13:25:29] keden: has joined #ruby
[13:35:26] agent_white: has joined #ruby
[13:47:12] dviola: has joined #ruby
[13:47:25] s2013: has joined #ruby
[13:52:48] larissa: has joined #ruby
[13:55:07] szulak_: has joined #ruby
[14:05:36] laaron: has joined #ruby
[14:17:58] comet23: has joined #ruby
[14:18:03] jcalla: has joined #ruby
[14:18:06] comet23: how do you wrap values around?
[14:18:27] comet23: like i have an array
[14:18:43] comet23: ['a','b','c']
[14:19:02] comet23: i want a counter to keep going back to a when it reaches c
[14:19:18] comet23: not get nil
[14:20:56] donofrio: has joined #ruby
[14:21:13] al2o3-cr: comet23: can you paste an example of input/output? (with comments)
[14:22:01] comet23: i don't have any code i just wanted to know for future reference
[14:23:10] al2o3-cr: you don't need a counter.
[14:24:20] phaul: class Array; def infinitie_each(&block); (1..).map { each }.inject(:+); end; end # :)
[14:24:24] al2o3-cr: &>> %w(a b c).cycle.to_a 5
[14:24:27] rubydoc: # => ["a", "b", "c", "a", "b", "c", "a", "b", "c", "a", "b", "c", "a", "b", "c"] (https://carc.in/#/r/5va1)
[14:26:21] mikecmpbll: has joined #ruby
[14:27:53] al2o3-cr: comet23: not sure what you mean otherwise.
[14:31:55] Mike11: has joined #ruby
[14:33:13] hays: why doesn't this work? [1,2,3].reduce([]) { |sum, n| sum.push(n) if n.odd? }
[14:33:56] phaul: &>> [1,2,3].reduce([]) { |sum, n| sum.push(n) if n.odd? }
[14:33:57] rubydoc: # => undefined method `push' for nil:NilClass (NoMethodError) (https://carc.in/#/r/5va5)
[14:34:28] al2o3-cr: hays: use each_with_object
[14:34:38] hays: yeah, i know, but why doesn't that work?
[14:34:54] szulak_: &>> [1,2,3].reduce([])
[14:34:54] rubydoc: # => [] is not a symbol nor a string (TypeError) (https://carc.in/#/r/5va6)
[14:35:03] phaul: if n is even then the block is nil
[14:35:10] phaul: then nil is assigned to sum
[14:37:05] phaul: &>> [1,2,3].reduce([]) { |sum, n| x = sum.push(n) if n.odd? ; p x }
[14:37:07] rubydoc: # => [1] ...check link for more (https://carc.in/#/r/5vab)
[14:37:25] bmurt: has joined #ruby
[14:37:34] al2o3-cr: hays: don't use reduce/inject like that.
[14:38:02] al2o3-cr: phaul: not to your answer ;)
[14:38:16] phaul: ah. :) nm
[14:38:18] hays: phaul: ah, yes
[14:38:29] hays: [1,2,3].reduce(Array.new) { |sum,n| n.odd? ? sum.push(n) : sum }
[14:38:39] hays: and that Array.new could be p[
[14:39:17] hays: al2o3-cr: yeah i know i can use select, or each_with_object
[14:39:37] bougyman: i was about to mention each_with_object
[14:39:38] bougyman: [1,2,3].each_with_object([]) { |n, sum| sum.push(n) if n.odd? }
[14:39:50] al2o3-cr: yeah select the very method for it ;)
[14:40:00] al2o3-cr: &>> [1,2,3].select &:odd?
[14:40:00] rubydoc: # => [1, 3] (https://carc.in/#/r/5vag)
[14:40:03] bougyman: but yeah, select is better
[14:40:40] hays: " reduce is so powerful that every other Enumerable function could be written using it."
[14:41:09] hays: i was just playing with that idea
[14:41:30] bougyman: haha, it's true.
[14:42:33] al2o3-cr: &>> ["Enumerable"].inject Object, :const_get
[14:42:33] rubydoc: # => Enumerable (https://carc.in/#/r/5vah)
[14:43:00] bmurt: has joined #ruby
[14:43:37] bougyman: just cause it can doesn't mean it should, though
[14:43:38] bougyman: [1,2,3].inject(0) { |sum, n| n.odd? ? sum += n : sum }
[14:43:45] al2o3-cr: &>> (1..10).inject :lcm
[14:43:46] rubydoc: # => 2520 (https://carc.in/#/r/5vaj)
[14:48:42] hays: do rubyists like inject over reduce i guess?
[14:50:00] al2o3-cr: &>> "loud".each_byte.with_object("") { |b, s| s << b ^= 32 }
[14:50:00] rubydoc: # => "LOUD" (https://carc.in/#/r/5vaq)
[14:50:08] lupine: I don't like either
[14:51:37] cschneid: has joined #ruby
[14:54:09] venmx: has joined #ruby
[14:54:18] clemens3: has joined #ruby
[14:54:37] al2o3-cr: hays: no, each to their own.
[14:56:04] al2o3-cr: hays: ask baweaver about reduce, he'll teach you loads of wizardry ;)
[14:58:10] laaron: has joined #ruby
[14:58:20] LichenStaff: has joined #ruby
[14:59:34] polishdub: has joined #ruby
[15:01:13] al2o3-cr: hays: the reason i like (inject) is for method injection as the name suggests.
[15:01:38] al2o3-cr: &>> (1..4).inject :fdiv
[15:01:39] rubydoc: # => 0.041666666666666664 (https://carc.in/#/r/5vaw)
[15:01:46] al2o3-cr: is the same as
[15:02:07] al2o3-cr: &>> 1.fdiv(2).fdiv(3).fdiv(4)
[15:02:08] rubydoc: # => 0.041666666666666664 (https://carc.in/#/r/5vax)
[15:03:19] laaron: has joined #ruby
[15:03:48] al2o3-cr: and never do [1,2,3].inject &:+, use :+ is a direct method call without creating a proc
[15:07:05] al2o3-cr: you'd hardly ever need inject/reduce if you used the Enumerable methods provided.
[15:07:09] hays: shouldn't there be @ on the functions in ratio? https://github.com/skmetz/poodr2/blob/master/2_10.rb
[15:07:28] Rapture: has joined #ruby
[15:07:29] Guest44017: has joined #ruby
[15:08:15] al2o3-cr: hays: no, because there is a setter method ofr chainring
[15:11:13] hays: and than can be simplified to : class Gear < Struct.new(:chainring, :cog) I think
[15:13:38] roshanavand1: has joined #ruby
[15:16:27] al2o3-cr: but i'd use Gear = Struct.new ....
[15:16:56] al2o3-cr: otherwise you'll have an anonymous class in the ancestory
[15:17:42] al2o3-cr: &>> Gear = Struct.new(:chainring, :cog) { def ratio; chainring / cog.to_f; end }; Gear.new(52, 11).ratio
[15:17:43] rubydoc: # => 4.7272727272727275 (https://carc.in/#/r/5vb4)
[15:17:47] davidw_: has joined #ruby
[15:18:30] BTRE: has joined #ruby
[15:19:08] RiPuk: has joined #ruby
[15:19:47] hays: collect also seems to be the same as map
[15:20:29] al2o3-cr: hays: it is an alias, yes.
[15:21:25] chouhoulis: has joined #ruby
[15:22:26] al2o3-cr: hays: there is many aliases ;)
[15:22:47] hays: also map.with_index seems like magic
[15:22:52] tdy: has joined #ruby
[15:23:43] al2o3-cr: it's a method on Enumertor class
[15:25:36] al2o3-cr: hays: Enumerator#with_index is so you can have an index other 0
[15:26:05] clemens3_: has joined #ruby
[15:26:41] hays: yeah, so .map returns an Enumerator, which still contains enough information to create an index
[15:27:14] roshanavand: has joined #ruby
[15:27:43] al2o3-cr: "which still contains enough information to create an index" ?
[15:29:06] al2o3-cr: hays: what does that mean?
[15:30:02] al2o3-cr: &>> Enumerator.instance_methods(false)
[15:30:03] rubydoc: # => [:each_with_index, :with_index, :with_object, :next_values, :each_with_object, :peek, :feed, :peek_v ...check link for more (https://carc.in/#/r/5vb5)
[15:30:23] hays: just trying to say that the Enumerator still has access to the array, so it can provide indices. I wasn't thinking of .map returning anything, which doesn't make sense
[15:31:49] donofrio: has joined #ruby
[15:32:10] phaul: hays, when those methods return an Enumerator they don't actually run the iteration yet (at the point of return). Enumerator just encapsulates a reference to them, and can call them later when they have a block. It's lazy.
[15:32:12] sgen_: has joined #ruby
[15:33:31] al2o3-cr: hays: simalar to generators in python.
[15:36:13] al2o3-cr: &>> e = (1..10).to_enum; [e.take(3), e.next]
[15:36:14] rubydoc: # => [[1, 2, 3], 1] (https://carc.in/#/r/5vb6)
[15:37:49] connermcd: has joined #ruby
[15:40:13] al2o3-cr: in 2.6 Numeric#step & Range#step returns an Enumerator::ArithmeticSequence class
[15:45:00] al2o3-cr: must be something to do with endless ranges.
[15:46:07] cschneid: has joined #ruby
[15:51:07] phaul: this aborts :( 2.step(by: 3).include? 7
[15:51:21] al2o3-cr: &>> Array.module_eval { def to_ruby() pack 'C*' end }; [82, 85, 66, 89].to_ruby * 3
[15:51:22] rubydoc: # => "RUBYRUBYRUBY" (https://carc.in/#/r/5vbh)
[15:51:36] al2o3-cr: phaul: how?
[15:51:50] phaul: its infinite loop
[15:51:54] garyserj: has joined #ruby
[15:52:14] phaul: ArithmeticSequence#include? could have been just simple modulo arithmetics
[15:52:26] phaul: but apparently not
[15:52:44] al2o3-cr: phaul: show me what you tested with
[15:53:16] phaul: ruby-2.6.0-rc2
[15:53:25] al2o3-cr: code i mean.
[15:56:28] al2o3-cr: phaul: yeah it fucks up.
[16:00:01] al2o3-cr: yeah, with the :to keyword space happens.
[16:01:08] al2o3-cr: phaul: file a bug my brother
[16:02:03] armyriad: has joined #ruby
[16:03:06] al2o3-cr: phaul: wouldn't modulo be off by 1?
[16:05:02] kaleido: has joined #ruby
[16:07:04] phaul: I don't know the purpose of that class, it doesn't seem to implement anything itself.
[16:07:57] al2o3-cr: phaul: it implements #last
[16:09:16] phaul: it seems it's coming along https://bugs.ruby-lang.org/projects/ruby/search?utf8=%E2%9C%93&scope=subprojects&q=ArithmeticSequence
[16:09:26] phaul: someone just added #sum
[16:17:00] al2o3-cr: ruby devs are gods!
[16:22:42] al2o3-cr: phaul: anymore?
[16:23:39] phaul: that's all I got :)
[16:24:07] al2o3-cr: that one got past me ;)
[16:24:47] davidw_: has joined #ruby
[16:28:32] al2o3-cr: phaul: this is a nice addition: RubyVM.resolve_feature_path
[16:29:24] al2o3-cr: RubyVM.resolve_feature_path #=> [:so, "/home/gr33n7007h/.rubies/ruby-2.6.0/lib/ruby/2.6.0/x86_64-linux/objspace.so"]
[16:30:54] hutch: has joined #ruby
[16:32:04] phaul: what is it for?
[16:33:33] al2o3-cr: phaul: it resolves paths from require 'blah'
[16:34:15] al2o3-cr: first is ext /rb|so/ then path.
[16:34:51] al2o3-cr: trust me this is a good feature.
[16:35:06] phaul: I take your word for it :)
[16:35:41] \void: has joined #ruby
[16:44:44] al2o3-cr: &>> require'fiddle';include Fiddle;x = Struct.new(:foo, :bar).new(:blah, :nah); 0.step(24,8).zip([8].cycle).map { |b| Pointer[Pointer[dlwrap x][*b].unpack1('Q')].to_value }
[16:44:46] rubydoc: # => [8196, #<Class:0x000055da179cdcd0>, :blah, :nah] (https://carc.in/#/r/5vbo)
[16:47:05] al2o3-cr: &>> require'fiddle';include Fiddle;x = Struct.new(:foo, :bar).new(:blah, :nah); 0.step(24,8).zip([8].cycle).map { |b| Pointer[Pointer[dlwrap x].ref[*b].unpack1('Q')].to_value }
[16:47:06] rubydoc: # => [#<struct foo=:blah, bar=:nah>, false, false, false] (https://carc.in/#/r/5vbp)
[16:47:49] garyserj: has joined #ruby
[16:57:36] agent_white: has joined #ruby
[16:58:32] kapil____: has joined #ruby
[17:00:19] al2o3-cr: phaul: this is infinite loop
[17:00:44] al2o3-cr: 0.step(8,0) ....
[17:01:27] phaul: that's a cute one.
[17:02:58] phaul: tbh I would expect it to raise ArgumentError
[17:03:15] clemens31: has joined #ruby
[17:03:24] phaul: &>> 0.step(to: 8, by: 0)
[17:03:26] rubydoc: # => #<Enumerator: 0:step({:to=>8, :by=>0})> (https://carc.in/#/r/5vbw)
[17:03:40] phaul: &>> 0.step(to: 8, by: 0).entries
[17:03:46] rubydoc: # => (https://carc.in/#/r/5vbx)
[17:04:01] hays_: has joined #ruby
[17:05:04] al2o3-cr: &>> (1..8).step 0
[17:05:07] rubydoc: # => #<Enumerator: 1..8:step(0)> (https://carc.in/#/r/5vby)
[17:05:24] al2o3-cr: &>> (1..8).step(0).entries
[17:05:25] rubydoc: # => step can't be 0 (ArgumentError) (https://carc.in/#/r/5vbz)
[17:05:55] sameerynho: has joined #ruby
[17:09:21] sanscoeur: has joined #ruby
[17:09:55] nchambers: has joined #ruby
[17:11:21] cschneid: has joined #ruby
[17:13:23] Madmanden: has joined #ruby
[17:13:29] darkhanb: has joined #ruby
[17:14:48] roshanavand: has joined #ruby
[17:15:09] clemens3: has joined #ruby
[17:17:11] Fusl: has joined #ruby
[17:20:37] clemens3_: has joined #ruby
[17:23:35] orbyt_: has joined #ruby
[17:23:49] hays_: has joined #ruby
[17:25:34] hutch: has joined #ruby
[17:26:48] havenwood: &>> ((0..0) % 0).size
[17:26:49] rubydoc: # => undefined method `%' for 0..0:Range (NoMethodError) (https://carc.in/#/r/5vc3)
[17:27:00] havenwood: #=> Infinity
[17:31:51] garyserj: has joined #ruby
[17:31:54] al2o3-cr: ((0..1) % 0).size #=> Inf
[17:32:08] blockchan: has joined #ruby
[17:32:57] al2o3-cr: had a good xmas havenwood
[17:33:19] havenwood: al2o3-cr: got a brand new Ruby as a present! \o/
[17:33:35] nchambers: havenwood: i really liked that infinite range operator (article). can't wait to use ruby 2.6!
[17:33:52] havenwood: nchambers: yay!
[17:34:03] al2o3-cr: havenwood: i got that early :)
[17:34:21] havenwood: al2o3-cr: ruby 2.7.0dev ;)
[17:34:26] neuraload: has joined #ruby
[17:34:32] al2o3-cr: havenwood: hehe ;)
[17:35:16] thejs: has joined #ruby
[17:35:24] blockchan: Hello everyone. I was wondering if anyone encountered this weird error with eventmachine I have. UDP socket does not receive packets from network, but when I send something from localhost it suddenly starts receiving packets from network correctly
[17:36:02] blockchan: I detailed everything on stackoverflow, but it has no views: https://stackoverflow.com/questions/53951899/eventmachine-udp-socket-listener-does-not-receive-data-from-network-needs-to-be
[17:45:00] clemens3: has joined #ruby
[17:46:25] hays_: has joined #ruby
[17:46:30] ellcs: has joined #ruby
[17:46:41] za1b1tsu: has joined #ruby
[17:49:41] Flaghacker: has joined #ruby
[17:53:39] blockchan: has joined #ruby
[17:57:57] LightStalker: has joined #ruby
[17:58:54] MasterAsia: has joined #ruby
[18:01:17] polishdub: has joined #ruby
[18:02:48] al2o3-cr: &>> "yipppee ki yay".reverse
[18:02:49] rubydoc: # => "yay ik eepppiy" (https://carc.in/#/r/5vc5)
[18:03:26] nchambers: yippee kayak other buckets
[18:04:39] al2o3-cr: nchambers: :)
[18:05:00] nchambers: i've been watching too much brooklyn 99
[18:06:01] mspo: blockchan: your program worked for me
[18:06:20] al2o3-cr: been drikning to much poish potato wine :D
[18:08:19] clemens3_: has joined #ruby
[18:08:26] cthulchu_: has joined #ruby
[18:09:16] tdy: has joined #ruby
[18:15:44] JoeA2552: has joined #ruby
[18:27:25] rubydoc: # => {"PATH"=>"/usr/local/bin:/usr/bin:/bin", "HOME"=>"/home/ruby", "USER"=>"ruby", "LOGNAME"=>"ruby"} (https://carc.in/#/r/5vc7)
[18:31:36] cthulchu_: actually I was wrong yesterday
[18:31:45] cthulchu_: blocks do have normal access to this
[18:31:57] cthulchu_: it's just in that particular case it didn't work
[18:32:14] cthulchu_: I fixed it, but I still don't know what was wrong with that code
[18:32:26] cthulchu_: if anyone can clarify it for me, it would be awesome
[18:33:29] cthulchu_: (and my fix is ugly, I don't like it)
[18:35:16] quipa: has joined #ruby
[18:39:38] quipa: has joined #ruby
[18:43:16] donofrio: has joined #ruby
[18:43:54] quipa: has joined #ruby
[18:44:47] uplime: cthulchu_: where was the code though
[18:45:35] cthulchu_: uplime, https://paste.ofcode.org/35MJgEypkzBg9m8PVHB2LUf throws me NoMethodError: undefined method `key?' for nil:NilClass on line 8
[18:45:53] donofrio: has joined #ruby
[18:46:38] cthulchu_: I had to do ugly temp_event = temp_event || {} in there to fix it
[18:47:06] uplime: i can see why you would want something a bit cleaner :D
[18:48:42] quipa: has joined #ruby
[18:50:10] cthulchu_: also, I have a different question. I have a hash and an array with hashes. I need to make sure that all the fields in this hash are present in each hash of the array. I'm gonna do this using two nested .each in one .select. It's three nested loops. I mean, I don't expect them to be too large, but the code becomes hard to read.
[18:50:27] cthulchu_: maybe there are hacks like hash.includes(hash)
[18:50:32] reber: has joined #ruby
[18:50:47] cthulchu_: although I need it to do regex inclusion
[18:50:50] cthulchu_: so I guess not
[18:51:02] cthulchu_: anyhow, will write a method for this
[18:54:08] quipa: has joined #ruby
[18:55:01] laaron: has joined #ruby
[18:56:37] Emmanuel_Chanel: has joined #ruby
[18:56:55] quipa: has joined #ruby
[18:57:45] quipa: has joined #ruby
[18:58:09] al2o3-cr: cthulchu_: deffo not json?
[18:59:18] cthulchu_: I think sometimes I do : instead of =>
[18:59:52] cthulchu_: but in that case everything is =>
[19:00:12] cthulchu_: ah, right, I do json when I need to pretty print
[19:00:53] cthulchu_: anyhow, I don't think it relates
[19:00:54] JoeA2552: has joined #ruby
[19:01:27] laaron-: has joined #ruby
[19:05:58] cthu|: has joined #ruby
[19:11:41] cthu|: I kinda hesitate to do nested selects
[19:11:47] cthu|: they have a weirdass syntax
[19:13:15] cthu|: okay, select is not the way to go
[19:13:34] cthu|: I guess I'll just do the old good each and select them manually
[19:14:03] cthu|: really, some of these blocks are just lame. don't know how you use them freely when they are so limited
[19:14:09] garyserj: has joined #ruby
[19:14:38] SeepingN: has joined #ruby
[19:23:33] clemens3_: has joined #ruby
[19:24:49] cthu|: there's arr.each that passes the object and there's arr.each_index that passes the index. Where's the one that passes both like hash.each?
[19:25:11] cthu|: ot I guess once we have an index, we don't need the val cuz we can get it pretty quickly?
[19:25:15] cthu|: guys, am I alone here?
[19:25:17] lupine: each_with_index
[19:25:39] cthu|: I don't see it
[19:25:42] cthu|: https://ruby-doc.org/core-2.2.0/Array.html#method-i-each
[19:26:15] cthu|: oh, maybe it's cuz I use 2.2
[19:26:18] lupine: >> [6,1,2,3].each_with_index { |a,b| puts "#{a} #{b}" }
[19:26:24] ruby[bot]: lupine: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[19:26:37] cthu|: I told you!
[19:26:39] lupine: >> puts [6,1,2,3].each_with_index { |a,b| puts "#{a} #{b}" }
[19:26:45] ruby[bot]: lupine: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[19:26:49] cthu|: read the error
[19:26:51] lupine: works fine locally, anyway, and rings a bell from 1.8.
[19:26:54] phaul: lupine: &>>
[19:27:01] lupine: &>> [6,1,2,3].each_with_index { |a,b| puts "#{a} #{b}" }
[19:27:01] rubydoc: # => 6 0 ...check link for more (https://carc.in/#/r/5vci)
[19:27:25] lupine: also consider more words per line, and fewer imprecations per minute
[19:28:35] cthu|: I'm kinda almost alone here
[19:28:56] clemens3: has joined #ruby
[19:28:59] cthu|: also don't like to use methods that are not in the doc. maybe you wrote yours locally
[19:31:27] tag: has joined #ruby
[19:34:09] cschneid: has joined #ruby
[19:35:25] roshanavand: has joined #ruby
[19:36:46] hays: has joined #ruby
[19:42:41] cthu|: If I have nested each, will break break me out of one or will it apply to all layers?
[19:42:46] cthu|: I presume it's the former
[19:43:39] BH23: has joined #ruby
[19:48:05] cthu|: just made this function: https://paste.ofcode.org/ZBj6J6WSpeLNAkxvgmkFEX Can you take a look at it and criticize?
[19:48:54] uplime: (asking as a beginner) why do you use .size == 0 instead of .empty?
[19:50:16] cthu|: a habit, but thanks
[19:50:24] cthu|: empty is cooler
[19:51:06] uplime: ruby might be the only language where i don't use .size == 0
[19:52:26] cthu|: yeah, that's the thing. If you get used to ruby's sugar, it may be problematic when you switch
[19:52:59] uplime: yeah, i don't blame you
[19:53:00] cthu|: so it may be a good idea to do it in the traditional
[19:55:07] Renich: has joined #ruby
[20:00:12] Guest44017: has joined #ruby
[20:00:42] hutch: has joined #ruby
[20:01:11] laaron: has joined #ruby
[20:18:52] lucasb: has joined #ruby
[20:19:03] roshanavand: has joined #ruby
[20:21:39] sarink: has joined #ruby
[20:25:17] jottr: has joined #ruby
[20:25:57] Nicmavr: has joined #ruby
[20:28:13] segy: has joined #ruby
[20:29:19] Rapture: has joined #ruby
[20:47:45] mistergibson: has joined #ruby
[20:48:31] tdy: has joined #ruby
[20:53:39] planigan: has joined #ruby
[21:01:03] laaron-: has joined #ruby
[21:02:20] cd: has joined #ruby
[21:04:55] SeepingN_: has joined #ruby
[21:09:13] tdy: has joined #ruby
[21:15:10] code_zombie: has joined #ruby
[21:15:28] uplime: has joined #ruby
[21:17:06] sarink: has joined #ruby
[21:21:16] cthu|: ruuuubyyyy! why are you so silent, ruby!
[21:21:30] cthu|: oh, it's probably Christmas
[21:27:20] cschneid: has joined #ruby
[21:28:08] hutch: has joined #ruby
[21:29:59] cthu|: folks, help me with this thingy
[21:30:03] cthu|: a["test"] << {"qwerty"=>"qwe"}
[21:30:51] cthu|: << can't create an object
[21:31:04] cthu|: I hoped it would make an array
[21:31:18] uplime: a = Hash.new []
[21:31:31] cthu|: I'm doing it in loop
[21:31:39] uplime: what does that have to do with anything?
[21:31:59] cthu|: cuz I would create a new [] in each iteration
[21:32:05] cthu|: wouldn't I?
[21:32:15] cthu|: I need to append to it instead
[21:32:19] uplime: it creates a new hash with the default value of []
[21:32:37] uplime: its no different than a = {}, except you're giving a default value
[21:32:38] cthu|: okay, I don't wanna do it explicitly
[21:33:01] cthu|: I look for something that would append object to existing key or create the key and an array
[21:33:19] uplime: so, Hash.new []
[21:33:31] uplime: for every key created, it creates an array
[21:33:31] cthu|: again, I'm not gonna do that in a loop
[21:33:39] cthu|: I don't need keys
[21:33:42] cthu|: I need one key
[21:33:45] cthu|: and one array
[21:33:55] cthu|: my iterations should append to an array
[21:34:08] cthu|: there is a chance that they won't need to append and then I don't need the key
[21:34:17] cthu|: so I don't wanna create it outside
[21:34:17] uplime: no, i have no idea what you're talking about
[21:34:37] cthu|: why would I even do Hash.new []
[21:34:49] cthu|: I can do a["test"] = []
[21:35:07] cthu|: which I don't want
[21:35:09] uplime: you said you would hope a["test"] << ... would make an array
[21:35:20] uplime: the hash will have to return an array for << to work
[21:35:49] uplime: you're already doing a = {}. i'm not sure what the issue is with replacing it with a = Hash.new []
[21:36:00] cthu|: cuz I always need a
[21:36:07] cthu|: but not always the []
[21:36:17] uplime: k, good luck i guess
[21:36:43] cthu|: in that loop I do testing. a["test"] has failed cases. if nothing fails, I don't need it
[21:36:54] cthu|: but it there is more than one failure, I need to append
[21:37:06] uplime: you can't append if there is not already an array there
[21:37:12] cthu|: I feel like it's a trivial issue and there should be a trivial solution
[21:37:17] cthu|: well I know that
[21:37:24] cthu|: but I hoped there was some hack
[21:37:33] cthu|: like a = a || ""
[21:38:20] cthu|: yes!!!!!!!!
[21:38:21] cthu|: (foo ||= []) << :element
[21:39:16] tiff: has joined #ruby
[21:39:55] cthu|: (object["cds_not_found"] ||= []) << val
[21:40:00] cthu|: looks gorgeous
[21:40:56] sarink: has joined #ruby
[21:48:31] phaul: &>> a = Hash.new []; a['uplime'] = true; a['phaul']
[21:48:32] rubydoc: # => [] (https://carc.in/#/r/5vd6)
[21:48:50] phaul: &>> a = Hash.new []; a['uplime'] << true; a['phaul']
[21:48:51] rubydoc: # => [true] (https://carc.in/#/r/5vd7)
[21:49:08] phaul: I messed up my example first time
[21:49:59] uplime: so im wrong
[21:50:13] phaul: with block it would work
[21:50:19] uplime: how do you create a hash with an Array being the d... ah thats what I was thinking of
[21:50:26] phaul: &>> a = Hash.new { [] }; a['uplime'] << true; a['phaul']
[21:50:32] rubydoc: # => [] (https://carc.in/#/r/5vd9)
[21:50:32] uplime: yep, my bad
[21:51:50] leftylink: unfortunately, you see that a thing has happened.
[21:51:55] leftylink: &>> a = Hash.new { [] }; a['uplime'] << true; a
[21:51:56] rubydoc: # => {} (https://carc.in/#/r/5vda)
[21:51:59] leftylink: the hash doesn't even contain anything at all
[21:52:13] leftylink: &>> a = Hash.new { |h, k| h[k] = [] }; a['test'] << true; a
[21:52:14] rubydoc: # => {"test"=>[true]} (https://carc.in/#/r/5vdb)
[21:52:55] leftylink: "It is the block's responsibility to store the value in the hash if required"
[21:53:58] phaul: fair point leftylink
[21:54:11] uplime: thanks leftylink
[22:01:04] laaron: has joined #ruby
[22:12:39] cthu|: this feeling when you finished a large piece of new functionality, but haven't yet run the code. And you try it and... it works just as you expect...
[22:13:01] cthu|: this feeling of "now I have to look to find where it fails" :(
[22:14:15] hutch: has joined #ruby
[22:15:36] justache: is this a welcoming channel
[22:17:08] jottr: has joined #ruby
[22:32:15] reber: has joined #ruby
[22:46:05] jottr: has joined #ruby
[22:47:52] johnny56_: has joined #ruby
[23:00:14] JoeA2552: has joined #ruby
[23:01:42] laaron-: has joined #ruby
[23:02:53] kapil____: has joined #ruby
[23:09:01] ellcs: has joined #ruby
[23:14:07] Paraxial: has joined #ruby
[23:17:16] horribleprogram: has joined #ruby
[23:17:21] horribleprogram: Fuck all of you
[23:32:40] powerbit: has joined #ruby
[23:38:14] powerbit: has joined #ruby