<adam12>
random-jellyfish: You'd have to benchmark this to see what's faster but iterating over it as an array might do it as well, depending on if there's leading whitespace ahead of the #
<leftylink>
indeed, we can see that `sub` removes just one occurrence.
<leftylink>
therefore, one suggestion may be to use String#gsub instead, which removes all of them
<random-jellyfish>
I don't want to reject entire lines
<random-jellyfish>
I just want to remove the comment
<random-jellyfish>
some comments can show up in the middle of a line
<random-jellyfish>
and continue until the end of line
<random-jellyfish>
but yes, gsub does the trick
<adam12>
random-jellyfish: Oh I see. So comments _anywhere_ and not just at the beginning of the line. I was thinking the latter.
<leftylink>
let us hope that there is not anything weird like a string containing a #, or any other context where # is not to be interpreted as starting a comment
<leftylink>
wishing luck!
<random-jellyfish>
no it's basically just a list of tests that I have to run in a regression, one per line
<random-jellyfish>
and I want to be able to add comments in the file to add some extra info or to comment out some tests that I don't want to run
<random-jellyfish>
there's won't be any #'s in the test names
dionysus70 has joined #ruby
<random-jellyfish>
but hey, thanks for the help!
dionysus69 has quit [Ping timeout: 265 seconds]
dionysus70 is now known as dionysus69
queip has quit [Ping timeout: 252 seconds]
queip_ has joined #ruby
leitz has quit [Quit: Leaving]
queip_ is now known as queip
<al2o3-cr>
random-jellyfish: String#delete
<random-jellyfish>
delete doesn't seem to take a regex as argument : TypeError (no implicit conversion of Regexp into String)
AJA4350 has joined #ruby
<al2o3-cr>
random-jellyfish: no, match with regex then delete line
<random-jellyfish>
I just want to delete the comment no the whole line
AJA4351 has joined #ruby
<al2o3-cr>
ah, right. then String#sub
<NL3limin4t0r>
random-jellyfish: Keep in mind that /#.*\n/ also removes the newline character, so you would have to use "\n" for the replacement. Alternatively you can use /#.*$/ keep in mind that this is greedy and you most likely want to use /#.*?$/ or /#[^\n]*/ but you still would have issues with the # character in string or symbol context.
<NL3limin4t0r>
The above /#[^\n*]*/ should have been /#[^\n]*$/
<random-jellyfish>
NL3limin4t0r that's true, I'll use /#[^\n]*\n/
AJA4350 has quit [Ping timeout: 268 seconds]
AJA4351 is now known as AJA4350
blackmesa has joined #ruby
cd has joined #ruby
wildtrees has joined #ruby
<NL3limin4t0r>
You can negate string context with something like: string.gsub(/(?<string>"(?:[^"\\]|\\.)*")|(?<string>'(?:[^'\\]|\\.)*')|#[^\n]*$/m, '\k<string>')
bhaubert has quit [Quit: bhaubert]
<NL3limin4t0r>
But that isn't fool proof and still doesn't work with things like heredoc.
<random-jellyfish>
I won't apply it to complicated text
<random-jellyfish>
just a list of test names...kind of like identifiers
<random-jellyfish>
one per line
<random-jellyfish>
and I want to be able to add some comments here and there
queip_ has joined #ruby
queip has quit [Ping timeout: 268 seconds]
queip_ is now known as queip
peirama has left #ruby ["ERC (IRC client for Emacs 26.3)"]
johnny56_ has quit [Ping timeout: 240 seconds]
<al2o3-cr>
?xy random-jellyfish
<ruby[bot]>
random-jellyfish: 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
bitwinery has joined #ruby
krawchyk has quit [Quit: krawchyk]
mre- has quit [Ping timeout: 240 seconds]
brendan- has quit [Ping timeout: 264 seconds]
jacksoow has quit [Ping timeout: 265 seconds]
jacksoow has joined #ruby
sandstro_ has quit [Quit: My computer has gone to sleep.]
brendan- has joined #ruby
sauvin has quit [Read error: Connection reset by peer]
queip_ has joined #ruby
queip has quit [Ping timeout: 240 seconds]
tsujp has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
queip_ is now known as queip
brendan- has quit [Ping timeout: 264 seconds]
AJA4351 has joined #ruby
bhaubert has joined #ruby
AJA4350 has quit [Ping timeout: 240 seconds]
AJA4351 is now known as AJA4350
freedom has joined #ruby
bhaubert has quit [Quit: bhaubert]
AJA4351 has joined #ruby
bhaubert has joined #ruby
AJA4350 has quit [Ping timeout: 240 seconds]
AJA4351 is now known as AJA4350
<al2o3-cr>
&>> test ?M, __FILE__
<rubydoc>
stderr: -e:4:in `test': No such file or directory @ rb_f_test - -e (Errno::ENOENT)... check link for more (https://carc.in/#/r/7wkt)
<al2o3-cr>
&>> test ?M, File.expand_path(__FILE__)
greengriminal has quit [Ping timeout: 264 seconds]
<rubydoc>
stderr: playpen: application terminated abnormally with signal 31 (Bad system call) (https://carc.in/#/r/7wku)
greengriminal has joined #ruby
mossplix has quit []
skx86 has joined #ruby
random-jellyfish has quit [Remote host closed the connection]
energizer has joined #ruby
bhaubert has quit [Quit: bhaubert]
ouemt has joined #ruby
yann-kaelig has quit [Quit: yann-kaelig]
<ouemt>
is "if A and B or C" evaluated as "if (A and B ) or C" or "if A and (B or C)"?
<leftylink>
(first of all, one should use && and || for boolean operations, and only use `and` and `or` for flow control) a useful mnemonic is to remember that `&&` is multiplication and `||` is addition. and since multiplication has higher precedence than addition, `&&` has higher precedence. why is it that `&&` is multiplication? because if we think of just 1s and 0s, if either signal is 0, the result is 0. thus
<leftylink>
`&&` is like multiplication
<ouemt>
leftylink: I appreciate the detail, but all I'm doing is translating some ruby code to python. The existing code uses "and" and "or" :/
<leftylink>
doesn't affect my answer.
<ouemt>
leftylink: so I can just substitute 'and' for '&&' in your answer? making the answer to my question "if (A and B ) or C" ?
<leftylink>
why don't we remove all doubt by checking in code?
<leftylink>
&>> b = [false, true]; b.product(b, b).all? { |a, b, c| (a and b or c) == ((a and b) or c) }
<leftylink>
shows how much I know about this language!!!
<ytti>
|| and && may work more to expectation
<leftylink>
they do
<leftylink>
this I know
<ouemt>
ytti: I wish the original author had used it
Fusl has quit [Excess Flood]
<ytti>
i've made that mistake few times
<ytti>
because or and and look better
<ytti>
and i like aesthethics
Fusl has joined #ruby
<leftylink>
well, that was my TIL I guess!
<leftylink>
if the question had never been asked, I would have never learned it!
<leftylink>
dang
<ouemt>
I'm struggling with reading your code leftylink I'm not a ruby dev, but playing around with an online editor makes it look like your original statement was right?
<leftylink>
no, counterexmaple
<leftylink>
&>> b = [false, true]; b.product(b, b).all? { |a, b, c| (a or b and c) == (a or (b and c)) }
<leftylink>
but at least it shows the spirit. using that as inspiration, one is able to perform one's own tests, and not rely on the help of the wrong leftylink. since leftylink was just publicly proven to be wrong, it is clear that leftylink cannot be trusted
<leftylink>
I am sorry for saying wrong things of course
<leftylink>
as I said, my TIL for the day
<ouemt>
leftylink, I don't understand your code, I don't do ruby. Can you just tell me if it should be "(A and B ) or C" or "A and (B or C)"?
<ouemt>
I'm trying to understand, but I'm python dev, lol
xco has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
shirak has joined #ruby
wilkir has joined #ruby
<leftylink>
as we can see from https://ruby-doc.org/core-2.6.3/doc/syntax/precedence_rdoc.html, the words `and` and `or` are of equal precedence. but, uhm, does someone know where in the docs it shows me whether an operator is left associative or right associative? I can't seem to find it anywhere
<leftylink>
apparently there's a table in the book "The Ruby Programming Language: Everything you need to know", but I would have thought there would be a table in the ruby docs too?
<leftylink>
I did not find the associativity in the included docs, since I did `grep -ri assoc ruby-2.6.3/doc | grep -v ChangeLog` and got nothing useful. I will see if ruby-2.6.5 has any change in the docs, though I find it unlikely it will have
suukim has quit [Quit: Konversation terminated!]
queip has joined #ruby
absolutejam2 has joined #ruby
ElFerna has joined #ruby
sagax has joined #ruby
rubydoc has quit [Ping timeout: 268 seconds]
<NL3limin4t0r>
ouemt: `and` and `or` have the same precedence and are executed from left to right. They are not the same as `&&` and `||` both have a mutch higher precedence and `&&` has a higher precendence then `||`.
<leftylink>
dang, `grep -ri assoc ruby-2.6.5/doc | grep -v ChangeLog` did not give more information about the associativity
akemhp_ has quit [Ping timeout: 265 seconds]
<al2o3-cr>
leftylink: i don't think it is documented.
<leftylink>
dang
energizer has left #ruby ["Leaving"]
clemens3 has joined #ruby
bvdw has quit [Read error: Connection reset by peer]
<al2o3-cr>
thus, the only docment recording associativity is the link i posted above.
<al2o3-cr>
*document
<al2o3-cr>
afaik anyway
bvdw has joined #ruby
poontangmessiah has joined #ruby
poontangmessiah_ has joined #ruby
poontangmessiah_ has quit [Remote host closed the connection]
poontangmessiah_ has joined #ruby
xco has joined #ruby
poontangmessiah has quit [Ping timeout: 268 seconds]
akemhp has joined #ruby
mossplix has quit [Remote host closed the connection]
mossplix has joined #ruby
mossplix has quit [Client Quit]
teardown has quit [Ping timeout: 240 seconds]
queip has quit [Ping timeout: 252 seconds]
queip_ has joined #ruby
queip_ is now known as queip
mossplix has joined #ruby
yann-kaelig has joined #ruby
<NL3limin4t0r>
al2o3-cr: Although this proves again that wikis are not to be trusted. Their description of &&= is wrong.
<NL3limin4t0r>
> &&= | A &&=B does A = A && B
<NL3limin4t0r>
Which should be: A &&= B does A && A = B
mossplix has quit [Remote host closed the connection]
<NL3limin4t0r>
Strangly their description of ||= is correct: A ||= B assigns B to A iff A is nil or false
mossplix has joined #ruby
mossplix has quit [Remote host closed the connection]
mossplix has joined #ruby
<NL3limin4t0r>
Which makes you wonder why they didn't copy that to the &&= description: A &&= B assigns B to A if A is **not** nil or false
<al2o3-cr>
NL3limin4t0r: strangely enough i didn't notice that.
freedom has quit [Remote host closed the connection]
mossplix has quit [Ping timeout: 250 seconds]
<NL3limin4t0r>
&>> module AccessorA; def a; puts "getter a called, current value: #{@a.inspect}"; @a; end; def a=(a); puts "setter a called, current value: #{@a.inspect}, new value: #{a.inspect}"; @a = a; end; end; obj = Object.new; obj.extend(AccessorA); obj.a &&= 1; obj.a = 2; obj.a &&= 3
<NL3limin4t0r>
^ shows that the setter is never called for `obj.a &&= 1`
mossplix has joined #ruby
freedom has joined #ruby
<al2o3-cr>
NL3limin4t0r: try pasting it again.
<phaul>
rubybot
<NL3limin4t0r>
&>> module AccessorA; def a; puts "getter a called, current value: #{@a.inspect}"; @a; end; def a=(a); puts "setter a called, current value: #{@a.inspect}, new value: #{a.inspect}"; @a = a; end; end; obj = Object.new; obj.extend(AccessorA); obj.a &&= 1; obj.a = 2; obj.a &&= 3
<phaul>
it's offline.. I look into it
<al2o3-cr>
phaul: oh, ok.
ElFerna has quit [Quit: Leaving.]
<NL3limin4t0r>
np, you can past the line in your own irb to see the results
<al2o3-cr>
i did and it's correct.
ske3bal has joined #ruby
<leftylink>
nice way to check
AJA4351 has joined #ruby
<leftylink>
the quickest way I thought of was a `[]=`
AJA4350 has quit [Ping timeout: 250 seconds]
AJA4351 is now known as AJA4350
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
johnny56_ has joined #ruby
ske3bal has left #ruby [#ruby]
ur5us has joined #ruby
xco has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ElFerna has joined #ruby
MinSrodowiska has joined #ruby
queip has quit [Ping timeout: 265 seconds]
teardown has joined #ruby
queip_ has joined #ruby
queip_ is now known as queip
ellcs has joined #ruby
brendan- has quit [Ping timeout: 276 seconds]
NL3limin4t0r has quit [Ping timeout: 240 seconds]
akem__ has joined #ruby
akem__ is now known as akem
brendan- has joined #ruby
akemhp has quit [Ping timeout: 240 seconds]
brendan- has quit [Read error: Connection reset by peer]
ouemt has left #ruby [#ruby]
ur5us has quit [Read error: Connection reset by peer]
NL3limin4t0r has joined #ruby
ur5us has joined #ruby
akem__ has joined #ruby
johnny56_ has quit [Read error: Connection reset by peer]
<havenwood>
At some point it's a naming question. Is the language alive or is a descendant of it alive? How about after hundreds of generations, assuming it survives that long?
<al2o3-cr>
we're here aren't we?
<havenwood>
I was thinking more Ruby after we're gone.
spectra has joined #ruby
<havenwood>
But yes, we're here. :)
<al2o3-cr>
havenwood: i don't think ruby is going anywhere
mossplix has quit [Remote host closed the connection]
<havenwood>
al2o3-cr: not anytime soon. in the distant future its progeny may be what survives. dunno! we don't have any history to reference for programming language evolution over centuries.
<al2o3-cr>
dying, anywhere. the BEST interpreted language by far.
<havenwood>
al2o3-cr: will it be in 3019? or will one of its descendants? or both? neither?
<al2o3-cr>
havenwood: all of the above ;)
<havenwood>
Larry Wall mentioned once that Perl 6 is designed to be an appealing language for an AI to master.
<al2o3-cr>
havenwood: absolutly true.
<al2o3-cr>
people underestimate ruby.
ElFerna has joined #ruby
dkmueller has joined #ruby
<al2o3-cr>
it's an interpreted language that can ... absolutly anything to a degeree.
drincruz has quit [Ping timeout: 276 seconds]
johnny56_ has quit [Ping timeout: 240 seconds]
<al2o3-cr>
havenwood: steep vs sorbet?
chalkmonster has quit [Quit: WeeChat 2.6]
<al2o3-cr>
sorbet for me
<havenwood>
al2o3-cr: sorbet seems further along but more obtrusive. i'm most interested in type-profiler, since I like free wins.
mossplix has joined #ruby
reber has quit [Read error: Connection reset by peer]
<havenwood>
al2o3-cr: tooling to just analyze your program seems nicer than annotations. i think i'd rather do parallel annotations rather than inline if we're doing annotations, but i don't feel strongly about that.
<al2o3-cr>
havenwood: so you don't feel strongly about: def foo(x ¬x, ¬y)?
<havenwood>
al2o3-cr: On first impression, I like to keep my code as-is and have something parallel for signatures
akemhp_ has quit [Ping timeout: 252 seconds]
akemhp has joined #ruby
<al2o3-cr>
havenwood: would you like it inline though?
<havenwood>
al2o3-cr: I don't want to knock it, but I don't see adding current Sorbet annotations to my code.
<havenwood>
al2o3-cr: But annotations could feel more native. I don't like it.
<havenwood>
"I hate annotations." -Matz
brendan- has quit [Read error: Connection reset by peer]
ElFerna has quit [Quit: Leaving.]
<al2o3-cr>
havenwood: you are your own, matz is his own? everyone got an opinion?
<havenwood>
al2o3-cr: i happen to agree with matz on this one
mossplix has quit [Remote host closed the connection]
<al2o3-cr>
havenwood: why?
jeremycw has joined #ruby
<havenwood>
al2o3-cr: with a level 1 profiler, the wins outweigh the losses - guaranteed
<havenwood>
al2o3-cr: there are no losses
<havenwood>
if my code stays the same and a tool and analyze it - awesome!
brendan- has joined #ruby
<havenwood>
between inline and parallel annotation, i feel parallel reflects it being opt in and not enforced
<al2o3-cr>
hmm... going with consensus?
AJA4351 has joined #ruby
<havenwood>
the two inline annotation tools that exist are both awesome, but not code I want to opt in to.
<al2o3-cr>
maybe it's right, maybe it's not?
<havenwood>
i'll use type-profiler if it ships with Ruby 3, of course.
<havenwood>
i hope there'll be something nice to opt in to for annotations for widely used programs that can take advantage of signatures
hutch1 has joined #ruby
AJA4350 has quit [Ping timeout: 240 seconds]
AJA4351 is now known as AJA4350
<havenwood>
i'm not in love with the current level 2 type profilers