laaron- has quit [Remote host closed the connection]
r29v has joined #ruby
tdy has quit [Remote host closed the connection]
SeepingN has quit [Quit: The system is going down for reboot NOW!]
idiocrash has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
nowhere_man has quit [Ping timeout: 252 seconds]
uplime has joined #ruby
johnny56_ has quit [Quit: johnny56_]
johnny56 has joined #ruby
jottr has joined #ruby
jottr has quit [Ping timeout: 245 seconds]
kapil____ has quit [Quit: Connection closed for inactivity]
m0w has joined #ruby
al2o3-cr-tmp has joined #ruby
al2o3-cr is now known as Guest5049
al2o3-cr-tmp is now known as al2o3-cr
spacesuitdiver has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
m0w has quit [Ping timeout: 244 seconds]
r29v has quit [Quit: r29v]
barg has joined #ruby
<barg>
How do I convert a nokogiri object alement into a string.. for example, if I am in IRB, and I do irb(main):159:0> a=doc.css('table')[0].css('tr')[0] then it shows
<barg>
=> #<Nokogiri::XML::Element:0x3fc15059233c name="tr" children=[#<Noko... If I do. a.to_s then it shows => "<tr><td colspan=\"2\" style=\"text-align:center\"><. Which isn't what I want.. I want that this string "#<Nokogiri::XML::Element:0x3fc15059233c name="tr" children=[#<Noko.." How do I get that string?
<phaul>
barg: try #inspect
laaron- has joined #ruby
hutch has joined #ruby
laaron has quit [Remote host closed the connection]
<phaul>
barg? did that give you what you wanted?
<barg>
thanks, probably, i have to test it
<barg>
i'm going up and downstairs at the moment doing two things at the same time
<domgetter>
Is there a way to pipe to irb? e.g. echo -e "hello\nworld" | irb
gix has quit [Ping timeout: 240 seconds]
<domgetter>
If I have to do it with something like ruby -r irb -e "require 'irb'" or the like, that's fine too, I just couldn't find any working examples online
laaron has quit [Remote host closed the connection]
braincrash has quit [Quit: bye bye]
braincrash has joined #ruby
goez has quit [Ping timeout: 260 seconds]
houhoulis has joined #ruby
nowhere_man has joined #ruby
cyberarm has joined #ruby
Emmanuel_Chanel has quit [Ping timeout: 240 seconds]
hutch has quit [Ping timeout: 244 seconds]
Emmanuel_Chanel has joined #ruby
goez has joined #ruby
<havenwood>
domgetter: ruby -e 'binding.irb'
<havenwood>
domgetter: ah, pipe to, gotcha
<havenwood>
domgetter: sec
hutch has joined #ruby
Emmanuel_Chanel has quit [Ping timeout: 250 seconds]
<leftylink>
well, you have a REPL at your disposal. you should strongly consider using it to evaluate some useful expressions
<leftylink>
for example, what would 'a-z'.include?('x') be?
<havenwood>
Swyper: 'a-z' doesn't expand to a range
<Swyper>
I don't know what a REPL is, leftylink
<havenwood>
?irb Swyper
<ruby[bot]>
Swyper: irb is "interactive ruby", it is part of ruby. You can run ruby code and see results immediately. it's useful for testing code. Also see ?pry, a gem which is a popular alternative to irb.
<Swyper>
so what this line should be doing is iterating through the list of all characters, and rejected those wherever the count == 1 and sending back a list a-z where none of the elements of the list are elements of the string
<havenwood>
Swyper: Checking for inclusion is a bit more straightforward than counting.
<Swyper>
jeez my logic here is so bad let me rewrite
<leftylink>
regarding "are elements of the string" - then logically, the code should include some reference to the string there.
<havenwood>
Swyper: Every character in 'a'..'z' is in 'a'..'z' so it's expected to be empty
<rubydoc>
# => ["a", "b", "c", "e", "f", "g", "h", "i", "j", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "w", ...check link for more (https://carc.in/#/r/5wb6)
<Swyper>
o-o
<eam>
in rspec I want to validate that the lines in a file either 1) don't have foo, or 2) if they have /foo/ that they also have /bar/
<eam>
what's the best approach?
<Swyper>
I think using regex in someway if you can but I'm not to good with Ruby xD
<leftylink>
I'd do something like `line !~ /bar/ || line =~ /foo` I suppose ?
<leftylink>
oh wait, other way around
<eam>
it's conditional, so not having either foo or bar is ok
<eam>
but if it has foo, it must have bar
<leftylink>
`line !~ /foo/ || line =~ /bar/` . I think I'm translating "P implies Q" right this time...
<eam>
I can do expect(file).to match(/foo.*bar/) but this doesn't allow for cases where foo isn't present
<eam>
do I need to just dump all the rspec syntax and do it in straight ruby?
Swyper has quit [Remote host closed the connection]
<leftylink>
if it must have some rspec syntax... you could use something like `expect(file.lines).to be_all { |line| line =~ whatever }`
<leftylink>
because `be_x` in general becomes `thing.x?`
<eam>
ooh, that gives me a block with arbitrary ruby? I can work with that
<eam>
I can just say { |line| line !~ /foo/ or line =~ /foo.*bar/
<eam>
thanks :)
tdy has quit [Ping timeout: 268 seconds]
<havenwood>
eam: or the new #match? is faster, since it doesn't set magic variables and such
<havenwood>
but there's no #not_a_match? inversion
<eam>
I was looking at match, but how do I -- yeah
<eam>
and the conditional of match A or B cases
<havenwood>
eam: Regexp.union
<eam>
what I'm trying to do is write a serverspec spec to ensure that any ext filesystem in /etc/fstab has errors=panic set
<eam>
havenwood: that just adds an | right?
<havenwood>
yup
<leftylink>
the error message for when the `be_all` is violated might be a bit less than ideal since it doesn't tell you exactly which line violated it. I might suggest something like `file.each_line { |line| next if line.include?('ext'); expect(line).to whatever }`
<havenwood>
eam: and it saves the end directives mix if any
roshanavand has quit [Remote host closed the connection]
<Swyper>
updated line is : if (songs[songs.index{song_name}] == songs[(songs.index(song_name))-1] || songs[songs.index(song_name)] == songs[(songs.index(song_name))+1])
<leftylink>
index{song_name}
<Swyper>
that should check the element before and after the array, and return false if any of those is is a match
roshanavand has quit [Remote host closed the connection]
<leftylink>
well, you look at all the ways in which your computed answer differs from the expected answer, and then you tackle them one by one. for example, you see that one_week_wonders returns "di" in the result, when it should. so you figure out why it does that, and fix that
<leftylink>
s/when it should/when it should not/
roshanavand has joined #ruby
<uplime>
is ruby 2.6 officially out yet? or is it still in an rc?
Swyper has quit [Remote host closed the connection]
<leftylink>
was the radition of releasing on christmases upheld?
<uplime>
i saw something was released on christmas!
<up|ime>
this name makes me think everything is addressed to me. :(
solocshaw has quit [Ping timeout: 272 seconds]
Swyper has quit [Remote host closed the connection]
KeyJoo has quit [Quit: KeyJoo]
<up|ime>
it's interesting you write it as a keyword rather than the python-choose-arg
<up|ime>
i get why they would make it a keyword if the other doesn't exist in ruby, but it'll still feel weird to write to me
despai has quit [Ping timeout: 250 seconds]
<uplime>
havenwood: thats where i learned about it actually
armyriad has quit [Quit: Leaving]
<uplime>
haha
<phaul>
seems I caused some confusion yesterday by calling 'a-z' a string range as opposed to a normal range. I did not know that it's called a glob, I had to call it something..
<phaul>
altough I made the distiction a couple of times
houhoulis has quit [Remote host closed the connection]
garyserj has quit [Quit: garyserj]
<phaul>
jhass: still here?
Swyper has joined #ruby
<Swyper>
is there a method to remove duplicates of a specific element in an array?
sandelius has joined #ruby
<Swyper>
uniq! removes all duplicates afaik
<sandelius>
"evening" everyone
<havenwood>
sandelius: hi!
<phaul>
sandelius: evening
<havenwood>
Swyper: You could do: group_by(&:itself).map(&:first)
Eiquoh has quit [Quit: WeeChat 2.3]
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
<Swyper>
is there another method that's simpler to remove all duplicates of a specific element, or remove all elements with a particular value in an array?
<phaul>
second one is easy.. #delete
<Swyper>
yeah and delete returns the deleted element so I could just add it back that way xD
<phaul>
so you have an Array, and an elem, and you want to remove all but first occurance of elem, I am assuming you need to keep it at original index as well? If not then yeah just add it back..
<Swyper>
I don't think its comparing the indexes if it then I will have to try another approach
<Swyper>
songs.new((delete("song")))
<havenwood>
Swyper: delete("song") #=> "song"
<Swyper>
whoops took out the quotes xD
<havenwood>
Swyper: But you're not calling #delete on an Array there ^ so it'll be NameError.
<Swyper>
so song needs to be an Array
<Swyper>
?
<phaul>
Swyper: the receiver of the delete method needs to be an Array.
<phaul>
In ruby you have objects then a . sign and then method name. That's how you send a method (or message) to an object
<Swyper>
songs.new((delete(song))), songs is an array and song is a string
hutch has quit [Ping timeout: 268 seconds]
<Swyper>
songs.new((delete("xyz"))), would work but have a variable thats a string would not
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Swyper>
I'm probably misunderstanding what everyone is saying >_>
<phaul>
let's take that apart. songs is the receiver. new is the method.
<phaul>
do you really wish to send the new method to songs? probablly not.
solocshaw has joined #ruby
<phaul>
usually ppl send the new message to classes to create new objects. When you already have an object, you don't send the new method to it. You can send other methods to it, like delete
<phaul>
when you just say a method name on it's own like you did with delete, it will be received by self. Whatever self is in that context.
<Swyper>
I get that the new keyword is probably for instantiating a new object like it is in other languages ;x
tiff has joined #ruby
cschneid has joined #ruby
<phaul>
in ruby everything (mostly) is receiver . method ; even if it doesn't look like it. It's really useful if you think about your methods that way. Who's receving it, and how the receiver handles it. In other words there are no procedures or functions. just methods (aka messages) sent to objects
barg is now known as garyserj2
garyserj2 is now known as barg
<Radar>
in really weird Ruby it can be things like 1::to_s
<Radar>
but that's really not standard at all
<Swyper>
okay so I tried this which is still wrong: songs.push(delete(song)) , songs is the the object which I am calling the push method on, the push method is supposed to give me the return value of delete(song)
al2o3-cr has joined #ruby
jottr has joined #ruby
<Swyper>
oh I see now where I am probably going wrong
<Swyper>
sec
cschneid has quit [Ping timeout: 246 seconds]
<Swyper>
songs.push(songs.delete(song)) also failed xD
nfk has joined #ruby
<phaul>
you are on the right track though
<Swyper>
a.delete("b") #=> "b", is an example given in the docs for delete
<Swyper>
I'm not seeing where m method is going wrong exactly
<Swyper>
oof I figured it out
reber has quit [Remote host closed the connection]
hutch has joined #ruby
garyserj has joined #ruby
solocshaw has quit [Ping timeout: 268 seconds]
tiff has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
tiff has joined #ruby
ellcs has quit [Ping timeout: 250 seconds]
uplime has quit [Quit: WeeChat 2.2]
Swyper has quit [Remote host closed the connection]
armyriad has joined #ruby
Swyper has joined #ruby
Swyper has quit [Remote host closed the connection]
sameerynho has quit [Ping timeout: 268 seconds]
cschneid has joined #ruby
dellavg_ has quit [Ping timeout: 250 seconds]
hutch has quit [Ping timeout: 244 seconds]
hutch has joined #ruby
cschneid has quit [Ping timeout: 272 seconds]
rkazak has joined #ruby
<barg>
I have an array of string names=["bob","tod","john"] Why does the following give an error names.each { |x| puts names[x]+"zzz" } ? it says TypeError: no implicit conversion of String into Integer
hutch has quit [Ping timeout: 246 seconds]
uplime has joined #ruby
<havenwood>
barg: `names` is an Array and `name` is a String.
nfk has quit [Quit: Try memory.free_dirty_pages=true in about:config]
<barg>
names[x] should be a string shouldn't it?
<barg>
sure 'asdf' is a string no question about that!
<barg>
(And Ihave no string called 'name' ;-)
<barg>
)
<leftylink>
x successively takes on the values "bob", "tod", and "jon"
<barg>
oh but I want x to take on the values 0,1,2
<leftylink>
therefore, the block evaluates names["bob"] which will cause the tyep error
<barg>
doh
<leftylink>
well, if you want it to take on the values 0, 1, 2, there's Array#each_index for that
cschneid has joined #ruby
<barg>
why does this not work [0..2].each { |x| puts names[x]+"zzz" }
<barg>
isn't x an integer from that range/array 0..2 ?
<barg>
this works [0..2].each { |x| puts names[x] }
Aqo has quit [Quit: ChatZilla 0.9.92-rdmsoft [XULRunner 35.0.1/20150122214805]]
<barg>
but as soon as I try to concatenate something onto names[x] it fails
<havenwood>
barg: What does the error say?
<barg>
TypeError: no implicit conversion of String into Array
<havenwood>
&>> [] + ''
<rubydoc>
# => no implicit conversion of String into Array (TypeError) (https://carc.in/#/r/5wdm)
<barg>
but names[x] should not be an array!
<havenwood>
barg: But it is!
<barg>
names is the array
cnsvc has joined #ruby
cnsvc_ has joined #ruby
<havenwood>
barg: Show the code that created `names`?
<leftylink>
x takes on the value 0..2, therefore names[0..2] is also an array