<comet23>
what i don't understand is why is it not returning 1 at the end
<status402>
comet23: What the function is doing is essentially to keep running itself until some condition is met. That means that the 1 is just part of the "whole result", if that at all makes sense.
<comet23>
no it doesn't
<comet23>
it doesn't because it breaks my understanding of ruby returning the last thing that's evaluated
discopatrick has joined #ruby
mutantkeyboard has joined #ruby
<phaul>
comet23 fwiw that method works fine here
jottr has joined #ruby
<status402>
comet23: It actually is returning the last thing that's evaluated, but 1 isn't that.
<comet23>
how is it not 1??
<status402>
You start out by asking your function "is my number, n equal to 1?", which it's not so you multiply n by the result of calling your function yet again, this time with 4.
vondruch has joined #ruby
<status402>
This continues until n actually is 1, at which point you start to gather up all the results of your function calls, so what you really have is a kind of pyramid shape of function calls.
<status402>
I'd be making a lot more sense if I could draw this, honestly.
<mutantkeyboard>
Do you guys use Ruby for anything other than Rails?
aupadhye is now known as aupadhye|brb
aupadhye|brb is now known as aupadhye
<comet23>
thank u
Aqo has joined #ruby
<TheBrayn>
mutantkeyboard: I'm using it for Puppet and general scripting
<TheBrayn>
I haven't done much web development with it at all
profetes has quit [Ping timeout: 250 seconds]
lxsameer has joined #ruby
<phaul>
mutantkeyboard: also inside the field of Ruby web development some ppl migrate to newer frameworks which either better fit how web development is changing, like sinatra, with single page apps or microservies, or have a cleaner design but still MVC like hanami.
<mutantkeyboard>
paul I've used haa
<mutantkeyboard>
hanami
<mutantkeyboard>
But was more like a general question. I come from a lower-level development (C++ middleware services), and just decided to replace the previous Python glue code with Ruby, so that's where the question comes from
cnsvc has quit [Ping timeout: 256 seconds]
mutantkeyboard has quit []
code_zombie has quit [Quit: Leaving]
fmccann has quit [Ping timeout: 250 seconds]
tiff has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
SeepingN has quit [Quit: The system is going down for reboot NOW!]
tiff has joined #ruby
status402 has quit [Read error: Connection reset by peer]
status402 has joined #ruby
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
_whitelogger has joined #ruby
garyserj has joined #ruby
esrse has quit [Quit: 안녕히계세요~]
comet23 has quit [Quit: Connection closed for inactivity]
status402 has quit [Quit: status402]
status402 has joined #ruby
garyserj has quit [Quit: garyserj]
adac has joined #ruby
bak1an has joined #ruby
<adac>
Hi there! Is there a method to get an array out of a simple regex such as for example: (string1|string2|string3)?
status402 has quit [Read error: Connection reset by peer]
status402_ has joined #ruby
<canton7>
adac, give us some sample input and sample output?
<adac>
canton7, actually the regex is simply: (string1|string2|string3) and the output would be simply: [string1, string2, string3] I know I could remove chars and simply split but maybe there is a direct method that is used for such things?
status402_ has quit [Quit: status402_]
status402 has joined #ruby
sonikspin has joined #ruby
<canton7>
what's the input?
AJA4350 has joined #ruby
status402 has quit [Read error: Connection reset by peer]
status402 has joined #ruby
<adac>
canton7, the imput is this regex string: (string1|string2|string3)
status402 has quit [Read error: Connection reset by peer]
status402 has joined #ruby
<up|ime>
adac : and the string you're matching?
<canton7>
you have two inputs: the regex, and the string the regex is applied to. You've only given us one of those two
<phaul>
i think adac wants to interpret regexp as a string. regexp is not matched but rather is the data
<adac>
yes from the regex I'd like to export the strings to an array
<adac>
the 3 strings in that regex should become an array
<adac>
of 3 items
<adac>
3 strings
<phaul>
well, #to_s and #scan
<canton7>
or something like 's[1..-2].split('|')' . Depends how much you want to check that the input is well-formed
masterasia has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<phaul>
to_s seems to insert some junk.. so be careful. that aside why would you want to do this
* canton7
has written regexes to parse regexes more times than he would have liked
<phaul>
I think parsing regexes with regexes falls into the same category as parsing anything complex like html with regexes. simply dont
<adac>
thanks for the hints!
<phaul>
well, this might be an xy thing, you havent told us why you are doing such a thing
<phaul>
?xy
<ruby[bot]>
it seems like you are asking for a specific solution to a problem, instead of asking about your problem. This often leads to bad solutions and increases frustration for you and those trying to help you. More: http://meta.stackexchange.com/a/66378
kapil____ has quit [Quit: Connection closed for inactivity]
<adac>
I think the solution to my issue is probably not to use regex in first place but define an array instead for such a simply case
<adac>
I first was thinkink I cannot validate an array in ruby on rails
<adac>
so I awanted to use a regex for validation
<up|ime>
if you're dealing with forms they can send arrays of data and/or json post bodies
<adac>
kk
szulak_ has joined #ruby
masterasia has joined #ruby
tiff has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Sembei has quit [Ping timeout: 240 seconds]
status402 has quit [Ping timeout: 250 seconds]
Fusl has quit [Remote host closed the connection]
bmurt has joined #ruby
Fusl has joined #ruby
sandelius has joined #ruby
<sandelius>
Hello everyone
<phaul>
hi sandelius
<phaul>
I heard it was windy over there, how are you holding up
kapil____ has joined #ruby
catbusters has joined #ruby
<catbusters>
Hi
<sandelius>
phaul I live in the south so it sure was windy but not that bad like other countries have it sometimes.
rawrg has quit [Remote host closed the connection]
<catbusters>
What's the resources block inside the scope block? I mean, it looks like calling a function inside another function
<catbusters>
Sorry for the noob questions
<sandelius>
catbusters it's exactly that tho your're calling a method from the scoped context
<sandelius>
it kinda works the same way as jsvascript
agent_white has joined #ruby
<catbusters>
So I'd be able to define multiple resources blocks inside the scope block?
<jhass>
sure, picture blocks as anonymous functions
<phaul>
hi, jhass, sorry for jumping on you as soon as you appear :) can you please update carc.in to 2.6 for our bot, when you have time? (in your own time, no rush)
sanscoeur has quit [Remote host closed the connection]
szulak_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Aqo has joined #ruby
sauvin has quit [Ping timeout: 245 seconds]
chouhoulis has joined #ruby
NingaLeaf has joined #ruby
scrptktty has joined #ruby
Swyper has joined #ruby
SeepingN has joined #ruby
conta1 has joined #ruby
tdy has joined #ruby
Swyper has quit [Remote host closed the connection]
conta1 has quit [Ping timeout: 244 seconds]
vikaton has quit [Quit: Connection closed for inactivity]
Rapture has joined #ruby
Xenosine has joined #ruby
Xenosine has left #ruby [#ruby]
s3nd1v0g1us has joined #ruby
hutch has quit [Ping timeout: 244 seconds]
hutch has joined #ruby
sanscoeur has joined #ruby
ua has quit [Remote host closed the connection]
tiff has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
maryo has quit [Ping timeout: 258 seconds]
conta has quit [Quit: conta]
NingaLeaf has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
NingaLeaf has joined #ruby
NingaLeaf has quit [Client Quit]
ua has joined #ruby
ivanskie has joined #ruby
<ivanskie>
hi all
dellavg_ has quit [Ping timeout: 258 seconds]
<ivanskie>
i have a what i think is a fairly common problem that I haven't dealt with yet, trying to wrap my head around. thought I might ask for suggestions here.
gnarmis has joined #ruby
bob_dino has joined #ruby
gnarmis has quit [Client Quit]
<ivanskie>
I'm using aws sdk, getting logs from cloudwatch logs. what i ended up doing was remap the messages hash to new hash like this: { timestamp: { message: '', instanceid: '' ...} since i will be collecting logs from several streams at once, i thought I'd push them all into a single hash, then do hash.keys.sort.each { |key| print hash[key].message } ( simplified for simplicity's sake)... so the issue i'm running into now, is when i
<ivanskie>
refresh and get logs. it re-prints the old ones in addition to new ones, within the request limit.. of lets say 100 records. so refreshes, adds lets say 5 new lines, and 5 oldest lines dissapear, but all existing just get reprinted..
<ivanskie>
so how can I check, and only print new records?
<havenwood>
ivanskie: I don't quite follow your example code. Can you show a simplified version of what you're doing that run?
<havenwood>
runs*
<ivanskie>
probably not in a shirt time.
cthulchu has joined #ruby
bmurt has quit [Ping timeout: 268 seconds]
<ivanskie>
i think i need to keep track of "old" records. and when new ones come in, only deal with new records.
<havenwood>
ivanskie: Your pseudo code has some inconsistencies and it's not clear which Hash you mean by `hash`.
<ivanskie>
like array of epoch timestamps
brendan- has quit [Ping timeout: 250 seconds]
<ivanskie>
ah alright let me put some code together one sec
<ivanskie>
on every request i get about 50 records from past few seconds.. then refresh using the "nextFordwardToken", which doesn't seem to be changing much, but thats a different issue alltogether.
<quiliro>
hello...is there some newbie tutorial for using ruby to communicate with an FTDI device?
<ivanskie>
so i'd like to just tail, and print only the new records, and not reprint old ones
m27frogy_ has quit [Read error: Connection reset by peer]
rubydoc has quit [Ping timeout: 250 seconds]
phaul has quit [Ping timeout: 240 seconds]
<havenwood>
ivanskie: Why `response.to_h` when `response` is already a Hash?
<ivanskie>
its json
<ivanskie>
i mean comes in as json
<ivanskie>
hm yeah good point i guess
<havenwood>
ivanskie: Where is `@events` defined?
<ivanskie>
its blank at init. then i add to it on every request
<havenwood>
ivanskie: This is a very hard example to follow, since it doesn't execute and references things that aren't here.
<ivanskie>
so within that block
<ivanskie>
one sec
<havenwood>
ivanskie: By "blank" do you mean it's an empty Hash?
<quiliro>
havenwood: thank you. i saw them but i do not understand...is there something tutorialish somewhere?
<havenwood>
quiliro: What are you trying to do?
rubydoc has quit [Ping timeout: 240 seconds]
<quiliro>
i want to communicate an avr via an ftdi to usb device to my computer
<quiliro>
it must just send bits: 01100101001 etc
<quiliro>
i have an idea of ruby already but it is very basic...perhaps it would be easier to learn though an exercise which involves what i need to achieve
Sina has quit [Quit: Connection closed for inactivity]
<quiliro>
-> send the data to the usb port
<havenwood>
quiliro: I don't know of any tutorials.
<havenwood>
baweaver: It's interesting there's NilClass#to_i, #to_h, #to_a, but no #to_int, #to_hash, #to_ary. I guess worry about masking bugs with implicit conversions?
<baweaver>
Pretty much.
brandonkal has joined #ruby
<ivanskie>
havenwood here's my actual code.. https://dpaste.de/zOv5#L157,158,159,163,165,166,167,168,169,170,171,172,173,174 i should be doing a comparison somewhere in there to determine only the new records. but not sure about the best way to do that. unless that means that the way i wrote that is already bad to begin with.
<ivanskie>
within the block on lines 163-174
<havenwood>
ivanskie: Put an if statement around line 158, checking if the timestamp is newer than last seen.
bob_dino has quit [Quit: bob_dino]
<ivanskie>
that takes care of not adding duplicates. but my print block is still flawed, i'll have to do something similar there
<ivanskie>
maybe add it to @new_events then only print @new_events
phaul has quit [Ping timeout: 268 seconds]
<ivanskie>
or rather do that with timestamps.. only make list of new timestamps
<ivanskie>
yaaa
cthulchu has quit [Ping timeout: 252 seconds]
rubydoc has joined #ruby
phaul has joined #ruby
cthulchu has joined #ruby
tdy has quit [Ping timeout: 246 seconds]
hurricanehrndz has quit [Ping timeout: 250 seconds]
cschneid has joined #ruby
hurricanehrndz has joined #ruby
cnsvc has joined #ruby
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
comet23 has quit [Quit: Connection closed for inactivity]
Scriptonaut has joined #ruby
<Scriptonaut>
have you guys noticed how in the ruby console, if you override an assignment method, it will always return whatever you assign it to, even if the method returns false?
<Scriptonaut>
I have a method that's like: def receive_notifications=(flag); User.current.is_admin? && super(flag); end
millerti has joined #ruby
<Scriptonaut>
in the console however, when User.current is a non-admin user, and I do: my_user.receive_notifications = true, the console prints "true" as the return value, even though I checked, and it's not true
<Scriptonaut>
should I raise an error instead?
<cschneid>
Does anybody have links to articles about tooling around ruby? We're using codeclimate, standardrb, and I'm looking at rufo for formatting - any others that people like? Trying to make sure a rapidly growing team stays relatively consistent
<mspo>
rubocop?
whathappens has joined #ruby
tomaw_ has joined #ruby
tomaw has quit [Read error: Connection reset by peer]
tomaw_ is now known as tomaw
despai has joined #ruby
Azure has quit [Ping timeout: 258 seconds]
conta has joined #ruby
conta has quit [Ping timeout: 268 seconds]
tdy has joined #ruby
Mike11 has joined #ruby
quiliro has left #ruby [#ruby]
<cschneid>
mspo: standardrb is a set of rubocop rules - so that's included yep. Anything else to look at that will let junior devs focus on the behavior & tests rather than accidental complexity?
<LadyElusive>
Scriptonaut: i think you're assigning a variable of the same name as the function, and assigning a variable returns what was assigned, thus true
s3nd1v0g1us has quit [Quit: WeeChat 2.2]
<LadyElusive>
also, the function you defined is "receive_notifications=" and not "receive_notifications"
tdy has quit [Read error: error:1408F119:SSL routines:ssl3_get_record:decryption failed or bad record mac]
<cschneid>
yep, that's the main app I'm worried about right now
<cschneid>
rails_best_practices gem looked old when I last looked
<havenwood>
cschneid: Yeah, it still has some interesting sections though. I tend to run it and largely disregard its output - but a few things worth looking at.
<havenwood>
cschneid: Brakeman for sure.
<havenwood>
cschneid: bundle-audit
tiff has joined #ruby
<havenwood>
cschneid: the bullet gem for N+1 queries and unnecessary eager loading
whathappens has quit [Remote host closed the connection]
nickjj_ has joined #ruby
<havenwood>
cschneid: ah, missing indexes is one nice rails_best_practices thing
chouhoulis has quit [Ping timeout: 268 seconds]
nickjj_ is now known as nickjj
<havenwood>
that matters soo mcuh
hutch has quit [Ping timeout: 250 seconds]
mustmodify has joined #ruby
<mustmodify>
I'm having brain problems.
<cschneid>
of for sure. I actually work at scoutapp.com - an APM. So performance, especially db, is what we do :)
<mustmodify>
I want an iterator that provides the n and the n+1st elements of an array
<mustmodify>
is that a thing? I guess I could write one...
<havenwood>
cschneid: hah, I was a Scout customer on Heroku
<havenwood>
cschneid: Nice stuff!
<cschneid>
Thanks :)
<havenwood>
mustmodify: each_cons
<cschneid>
havenwood: And thank you for the ton of linters I get to go track down and implement!
<havenwood>
cschneid: AccessLint for accessibility CI
<Scriptonaut>
LadyElusive: no I overrode the receive_notifications= method. THen I call super inside of it. The method returns false, I've tested it, but for some reason the console (only in the console, not when it runs anywhere else) short-circuits and displays the return value as whatever you pass to it. With a normal assignment method this is expected behavior, but I overrode the method and changed how it worked
nickjj has quit [Client Quit]
<Scriptonaut>
I'll gist the actual code
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
hutch has joined #ruby
nickjj has joined #ruby
spacesuitdiver has joined #ruby
despai has joined #ruby
spacesui_ has quit [Ping timeout: 240 seconds]
CrazyEddy has quit [Read error: Connection reset by peer]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Eiam>
in console whats your staff.first.is_admin? value
CrazyEddy has joined #ruby
<Eiam>
your first line makes it sound like that value is false, since line 3 shows false. if is_admin is false, the next call will be false && super(true) which can only return false
<Eiam>
Scriptonaut: ^
phaul has quit [Ping timeout: 258 seconds]
orbyt_ has joined #ruby
rubydoc has quit [Ping timeout: 245 seconds]
<Eiam>
so then its false && super(true) as the return value on line 4, which we already established must be false because it says false in your output.
<Scriptonaut>
Eiam: exactly
<Scriptonaut>
that's why I'm confused
<Eiam>
right so I don't get the bug
<Scriptonaut>
why is the console displaying true, when it's false
<Eiam>
its working exactly as the code says
<Scriptonaut>
no it's not, look at line 6
<Scriptonaut>
it returns true
<Eiam>
oh, something to do with how irb echos statements or something
<Eiam>
i don't think thats the return value of your statement
<Scriptonaut>
when I do: ret_val = (gu.receive_direct_message_alerts = true), ret_val is assigned true
<Scriptonaut>
only in the console though, when I run it on unicorn or even just through the interpreter it returns false
<Eiam>
whats the implementation of receive_direct_message_alerts
* baweaver
wanders in
tiff has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Scriptonaut>
Eiam: it's a cp_typed_hash on an ActiveRecord 2 model
<Scriptonaut>
the method I wrote is to override the setter to prevent non-admins from having that setting set to true
<Eiam>
i mean do you have receive_direct_message_alerts and receive_direct_message_alerts=
* baweaver
kinda thinks this sounds like Rails
<Scriptonaut>
baweaver: it's not
<Eiam>
because it looks like you are calling two different implementations and wondering why each has its own return value
<Scriptonaut>
Eiam: I explicitly wrote the setter, the getter was defined by cp_typed_hash
<Eiam>
but I only see one implementation, receive_direct_message_alerts=
<Scriptonaut>
Eiam: yes, I wrote that
<Scriptonaut>
and then call super, to the setter that was defined previously
<Scriptonaut>
method overriding
<Scriptonaut>
I only call super if the user is an admin though
<Scriptonaut>
this is an issue with irb, the code is working as it should, it's just that in irb the return value is true when it should be false
<Scriptonaut>
I wonder if it's a bug in old irb, this is ruby 1.8.7
<Eiam>
okay... what I'm saying is you could be calling "methodA" and it gives you false. later you call "methodB" and it gives you true, then you again call "methodA" and it gives you false again, which is expected...
<Eiam>
receive_direct_message_alerts and receive_direct_message_alerts= aren't the same method , they could be defined totally different
<Scriptonaut>
what?
<Scriptonaut>
I gisted a console session, I am not confusing the getter and setter
<Scriptonaut>
there, that's plain ruby, no activerecord, no method overriding
<Scriptonaut>
it still has the issue
<Scriptonaut>
as you can see, on line 6, the method x= should always return false
<Scriptonaut>
however on line 15 it returns true
<Scriptonaut>
when I do: t.x = "foo bar", it returns "foo bar"
<Scriptonaut>
I'm gonna try in ruby 2.5 and see if the issue is still there
hiroaki has quit [Ping timeout: 252 seconds]
drale2k_ has joined #ruby
<Scriptonaut>
hmm, still happens with ruby 2.5.1. It must just be the way the console is written. I always thought that the => in the console was supposed to denote the return value, but when the method ends with a '=', it returns the RValue no matter what
<Scriptonaut>
oh well, it's not a big deal, the code works. I just thought that was weird
rubydoc has joined #ruby
<Eiam>
if you split your assignment out into its own line
<Eiam>
the behavior will change
<Eiam>
i thought assignment in comparisons were frowned upon
<Eiam>
on line 6 if you set @x = flag, then do false && @x you'll see it shifts
<Scriptonaut>
well that would change the behavior because that's totally different code. The assignment in your example wouldn't be dependent on the first argument to &&
<Scriptonaut>
that would assign @x to flag no matter what
<Scriptonaut>
I came up with an even simpler example
<Scriptonaut>
def foo=(bar); false; end
<Scriptonaut>
f = true # This returns true
<Scriptonaut>
foo = true **
<Scriptonaut>
even though the method :foo= just returns false
<Eiam>
oh you are counting on the early exit to avoid the assignment
<Eiam>
ha ha
<Eiam>
righto
<Eiam>
Scriptonaut: yeah, that is interesting
<Scriptonaut>
ya, pretty much. In my actual program I'm not doing condition && foo = bar, I'm just calling super(flag)
<Eiam>
i don't know why you are seeing that behavior in console
<Scriptonaut>
ya, it's odd
phaul has joined #ruby
Dbugger has quit [Remote host closed the connection]
Nicmavr has quit [Read error: Connection reset by peer]
hutch has quit [Ping timeout: 240 seconds]
Inline has quit [Read error: Connection reset by peer]
Nicmavr has joined #ruby
hutch has joined #ruby
Yxhuvud has joined #ruby
polishdub has quit [Remote host closed the connection]
waheedi has joined #ruby
<waheedi>
is rubygems.org down for fetching gems or versions?
<waheedi>
or its a deployment on a late friday
<waheedi>
or it could be my poor internet connection, timing out :)
<waheedi>
Exception `Gem::RemoteFetcher::UnknownHostError' at /usr/local/rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems/remote_fetcher.rb:276 - timed out (https://rubygems.org/api/v1/dependencies)