havenwood changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 3.2.2, 3.1.4, 3.0.6, 3.3.0-preview1: https://www.ruby-lang.org | Paste 4+ lines to: https://gist.github.com | Books: https://t.ly/9ua4 | Logs: https://libera.irclog.whitequark.org/ruby/
sickdyd has quit [Quit: WeeChat 3.8]
Dooky has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
gonix has quit [Ping timeout: 240 seconds]
<isene> weaksauc_: 3.0.2p107
Dooky has joined #ruby
Dooky has quit [Client Quit]
<weaksauc_> isene those docs are for 2.5
NightMonkey has quit [Ping timeout: 264 seconds]
NightMonkey has joined #ruby
<KOTP> isene, if possible generate documentation for your intalled version of ruby and you will always have access to your documentation tailored (generated) for your version specifically.
Dooky has joined #ruby
hansolo has quit [Remote host closed the connection]
hansolo has joined #ruby
Sheilong has joined #ruby
pookie has joined #ruby
<isene> KOTP: How do I do that? And how do I access it?
<ox1eef_> YARD has built-in support for that.
egality has quit [*.net *.split]
Artea has quit [*.net *.split]
balo has quit [*.net *.split]
dorian has quit [*.net *.split]
olspookishmagus has quit [*.net *.split]
Bitflux has quit [*.net *.split]
dcx has quit [*.net *.split]
asio has quit [*.net *.split]
<mooff> on Debian.. apt install ri
<mooff> then you can `ri ARGF`, for example
egality has joined #ruby
Artea has joined #ruby
balo has joined #ruby
dorian has joined #ruby
asio has joined #ruby
Bitflux has joined #ruby
dcx has joined #ruby
dcx has quit [Max SendQ exceeded]
Artea has quit [Max SendQ exceeded]
Bitflux has quit [Max SendQ exceeded]
Byteflux has joined #ruby
dcx has joined #ruby
Dooky has quit [Quit: Textual IRC Client: www.textualapp.com]
Arty has joined #ruby
<isene> +1
jhass has quit [Ping timeout: 240 seconds]
<johnjaye> does ruby have explicit casting
<johnjaye> like if i wanted to convert x=2.5 to an integer to call succ on it, can i cast it to integer
<ox1eef_> You can use Float#ceil, Float#floor, or Float#to_i.
<mooff> only through asking an object to convert itself
<johnjaye> right but i meant like in java where you just force a type to something
<johnjaye> as in (float)(x) --> now x is float
<mooff> there is .to_i on almost everything
<mooff> try `ri String#to_i
<mooff> = 5.0.to_i.succ
<ruby-eval> => 6
<mooff> btw isene..
<ox1eef_> Java is not comparable in this case. There is no strict typing. You can turn a float into an integer with the above mentioned methods. You can't treat 2.5 as an integer, because the concept doesn't exist in Ruby and in strictly typed languages there would most likely be coercion rules that define what 2.5 becomes (ie 2 or 3).
<mooff> = alias :system_backticks :`; def `(cmd) = case cmd; when /^ri (.+)/ then "Documentation for #{$1}" end
<ruby-eval> => :`
<mooff> = `ri String.foo`
<ruby-eval> => "Documentation for String.foo"
<mooff> a variable is *always* like it was of type Object in Java, yeah
<johnjaye> so if i have x and i want to call an method should i just test if it responds to it ?
<mooff> yeah, that's reasonable
<ox1eef_> Generally, yes, in practice you will find is_a? is used regularly, and that acts more like a type check.
<mooff> there are some global methods for converting in Ruby, that can help, when you don't know what kind of object you are getting
<johnjaye> is is_a? identical to just calling x.class
<mooff> strangely, but also kind of nicely, they're named String(), Float(), etc
<ox1eef_> No. It asks the object if it is a certain class / module, and if any of its ancestors are as well.
<ox1eef_> Something like: [obj.class, obj.class.ancestors].include?(SomeClass)
<mooff> we were able to simplify the code for that float parsing benchmark the other day, by using Float(input_var, exception: false)
<johnjaye> i see
<mooff> it checks if input_var is a number, or a String, or otherwise knows how to floatify itself (responds to .to_f)
<ox1eef_> Something like: [obj.class, *obj.class.ancestors].include?(SomeClass)
<mooff> then it Does The Right Thing but from C, so it's faster
<mooff> if it can't be converted (e.g. Float("dog")), it raises ArgumentError by default
<mooff> but if you pass exception: false, then it returns nil for that instead
<mooff> = x = Float("foo"); if x then x + 1 else "didn't convert" end
<ruby-eval> ERROR: invalid value for Float(): "foo"
<ruby-eval> <internal:kernel>:173:in `Float'
<mooff> = x = Float("foo", exception: false); if x then x + 1 else "didn't convert" end
<ruby-eval> => "didn't convert"
<johnjaye> i was going to ask if you could treat nil as false somehow using that. but apparently that is the default in ruby anyway
<ox1eef_> "foo".to_f will return nil, and exceptions are not always desirable. So you can say, if "foo".to_i.nil?; puts "not an int"; end instead. And yes, nil and false are the only false values in Ruby.
<ox1eef_> My mistake. "foo".to_i returns 0.
<johnjaye> how do you check the empty string in ruby
<johnjaye> other than something like str.length==0
<leftylink> pandabot: ri String#empty?
<ox1eef_> str.strip.empty?
<mooff> johnjaye: specifically, only nil and false are actually false in a boolean context
<johnjaye> right
<mooff> 0, 0.0, {}, [], Object.new, all truthy
<johnjaye> so on a string i'd have to to check empty
<johnjaye> hmm. maybe i should define is_really_false? which converts all those to false
jhass has joined #ruby
<leftylink> why? they're not false so why should they be treated as such?
<mooff> = [0, 0.0, {}, [], Object.new].all? { |v| v }
<ruby-eval> => true
<johnjaye> well for example in lisp where nil and the empty list are identified, often you'll write a loop which pops elements out of a list and only stops when it is empty
<leftylink> well, you do that with just `widgets.each { |widget| act(widget) }` or `while (widget = widgets.pop); act(widget); end`
<leftylink> as we can see, that while loop takes advantage of the fact that nil is falsey. if [] were falsey, then the while loop would do the WRONG behaviour if widget were a []. this is why [] should not be falsey.
<johnjaye> oh it has nice semantics. it returns nil instead of an error when the list is empty
<mooff> Rails adds Object#blank?, and then defines it for String, Hash, etc
<mooff> it would be really good in the stdlib
<mooff> same with Object#try
<johnjaye> are you going to say that Object#blank? does essentially what I said earlier?
<mooff> yes. except, no number is blank :D
<mooff> `gem install activesupport`, then `irb -r active_support/all`, if you want to play
<mooff> reading ActiveSupport, too, was one of the best experiences of my programming life.
<mooff> just the docs.
<mooff> (and clicking "View Source" there some times)
<johnjaye> i see...
<mooff> several of the methods they defined have already made it into core Ruby
<johnjaye> apparently i have to sudo gem install
<mooff> try gem install --user
<johnjaye> otherwise i don't have write permissions on the /var/lib/gems/2.7.0 directory
<mooff> but sudo apt install ruby-activesupport would also be reasonable
<johnjaye> ok. i'm not sure what the convention is
<johnjaye> python has some weird virtualenv thing i've never understood.
<mooff> any is good, imo
<johnjaye> other languages people use often the distro provided package
<mooff> i haven't needed virtual Ruby environments since last using Rails
<johnjaye> it warned me that i dont' have ~/.local/share/gem/ruby/2.7.0/bin in my path. i cannot run gems. but that folder doesn't even exist.
<johnjaye> apparently it installed the gems to ~/.local/share/gem/ruby/2.7.0/gems
<mooff> all good
<mooff> activesupport's relatively forward and backward compatible
<johnjaye> what exactly is a virtualenv and why is everyone so fanatical about them
<mooff> isolates the libraries installed for a given Python or Ruby project
<johnjaye> so like it copies them?
<mooff> they get the standard library, but only whichever gems or Python packages you install in that environment
<mooff> so there's no potential for the system Python to influence a project's Python
<johnjaye> that only makes sense if gems often conflict with each other
jhass has quit [Ping timeout: 240 seconds]
<mooff> they don't, outside of web dev, imo
<johnjaye> i could see if you needed to fix a particular library version maybe
jhass has joined #ruby
<mooff> where your system Ruby is 2.7.0, i would encourage upgrading to a newer release of your OS :)
<mooff> 2.7.0 is the version on Debian 11, right?
<mooff> 2.7.4
<johnjaye> yes. what debian declares, I must use.
<johnjaye> unless compiling ruby is not too hard
<johnjaye> then i could try that
<mooff> bookworm is as stable as it is going to be for launch :)
<mooff> it's been frozen since Jan or Feb. release next couple of weeks
<mooff> also yes, that is relatively friendly
<mooff> it just "make install"s nicely to /usr/local etc
<johnjaye> oh ok. then i'll try it.
<johnjaye> so many projects surprisingly don't even do that much
<mooff> yeah. Ruby is just a ./configure && make && make install
<mooff> make -j4 :)
<johnjaye> "to build our project type ./blargfoo in the main dir, then make PLATFORM=hurblegurble and finally run configure git submodule init"
<mooff> yes. don't forget to install the snarglewurtschler, which can darnglewizz the snooglesnapthes
<johnjaye> my favorite one is a project that builds and runs perfectly fine on arm. but there is no option to explicitly say to build for it.
<johnjaye> instead you pass the option NOX86=1
<mooff> that'll auto-wangle your curbobitses into hard emblaggon, for upservence swangling
<mooff> don't mention autotools --host --build --target matrices
<johnjaye> haha. well autotools may have drawbacks. but every build system probably does.
<johnjaye> building software is a lot messier than i thought it was
<mooff> yeah, certainly
Sheilong has quit []
<hexology> wow, chruby and ruby-install *are* really nice
<hexology> i wish i had this for python now
<hexology> oh, speaking of which. johnjaye i almost always use a "version manager" for any language runtime that has one. i tend to ignore whatever is in my package manager except where it's required as a dep for other packages
<hexology> i'm not much of a ruby user (yet) but it's been my successful experience with python, node, etc
<hexology> something like chruby but for python seems like a great project
<johnjaye> you mean the venv stuff in python?
<johnjaye> one of the things i like about ruby vs python is it always does "the right thing" (TM) more often
<johnjaye> but that might just be my lisp prejudice showing
<johnjaye> like to_s taking a parameter to specify the number base. finally, common sense string manipulation
<mooff> that's not the case for e.g. HTTPS or SSL verification
<mooff> the module i made for IIRC was hard-fought. it's *hard* to dial SSL, with hostname and peer authentication, in Ruby
jhass has quit [Ping timeout: 240 seconds]
<johnjaye> what module did you make?
jhass has joined #ruby
johnjaye has quit [Ping timeout: 240 seconds]
asio has quit [Ping timeout: 260 seconds]
asio has joined #ruby
johnjaye has joined #ruby
<johnjaye> is "e".ord equivalent to "e".getbyte(0)?
<johnjaye> or does it fail for non-ascii
agent_white has joined #ruby
johnjaye has quit [Ping timeout: 256 seconds]
johnjaye has joined #ruby
<gr33n7007h> isene: yeah, they're not documented at all.
<gr33n7007h> I had to look at the source code.
<gr33n7007h> isene: you've done the same trick ;) line 504 Dir.exists? should be Dir.exist? 👍
ur5us has joined #ruby
<mooff> = ["e".ord, "e".getbyte(0)]
<ruby-eval> => [101, 101]
<mooff> anyone can use = here btw
<Shell> = ["👍".ord, "👍".getbyte(0)]
<ruby-eval> => [128077, 240]
crespire1 has joined #ruby
crespire has quit [Killed (NickServ (GHOST command used by crespire1))]
reset has quit [Quit: reset]
shokohsc6 has joined #ruby
shokohsc has quit [Ping timeout: 256 seconds]
shokohsc6 is now known as shokohsc
ur5us has quit [Ping timeout: 240 seconds]
jvalleroy has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
szkl has joined #ruby
jvalleroy has joined #ruby
johnjaye has quit [Ping timeout: 256 seconds]
johnjaye has joined #ruby
gr33n7007h has quit [Ping timeout: 240 seconds]
gr33n7007h has joined #ruby
Linux_Kerio has joined #ruby
crespire1 has quit [Ping timeout: 248 seconds]
crespire1 has joined #ruby
_ht has joined #ruby
gr33n7007h has quit [Ping timeout: 250 seconds]
infinityfye has joined #ruby
infinity_fye has joined #ruby
infinity_fye has quit [Remote host closed the connection]
gr33n7007h has joined #ruby
infinity_fye has joined #ruby
infinityfye has quit [Killed (NickServ (GHOST command used by infinity_fye))]
infinity_fye is now known as infinityfye
luffy[m] has quit [Remote host closed the connection]
weaksauce has joined #ruby
weaksauc_ has quit [Ping timeout: 248 seconds]
Linux_Kerio has quit [Read error: Connection reset by peer]
Linux_Kerio has joined #ruby
ur5us has joined #ruby
otisolsen70 has joined #ruby
ur5us has quit [Ping timeout: 240 seconds]
infernix has quit [Read error: Connection reset by peer]
szkl has quit [Quit: Connection closed for inactivity]
infernix has joined #ruby
ua_ has quit [Ping timeout: 240 seconds]
ua_ has joined #ruby
hrberg has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
hrberg has joined #ruby
crespire has joined #ruby
crespire1 has quit [Ping timeout: 240 seconds]
polishdub has quit [Ping timeout: 240 seconds]
polishdub has joined #ruby
shokohsc1 has joined #ruby
shokohsc has quit [Ping timeout: 268 seconds]
shokohsc1 is now known as shokohsc
<ox1eef_> chruby is especially nice. I don't remember ruby-install that well.
friendlypunk has joined #ruby
agent_white has quit [Remote host closed the connection]
friendlypunk has quit [Remote host closed the connection]
friendlypunk has joined #ruby
Prodigy has joined #ruby
lena64t has joined #ruby
Prodigy has quit [Quit: WeeChat 3.8]
perrierjouet has quit [Quit: WeeChat 3.8]
perrierjouet has joined #ruby
perrierjouet has quit [Quit: WeeChat 3.8]
perrierjouet has joined #ruby
ur5us has joined #ruby
otisolsen70 has quit [Quit: Leaving]
_ht has quit [Remote host closed the connection]
szkl has joined #ruby
Linux_Kerio has quit [Ping timeout: 248 seconds]
reset has joined #ruby
Sankalp- has joined #ruby
Sankalp has quit [Ping timeout: 240 seconds]
Sankalp- is now known as Sankalp
<hololeap> I haven't used ruby much in a while, but I remember there was some gem I would use in combination with nokogiri to do some basic web page scraping. any ideas what it might have been?
<hololeap> it could do basic http(s) stuff, store cookies, and the like
ox1eef_ has quit [Ping timeout: 240 seconds]
<hololeap> ok, I think it might have been mechanize
<weaksauce> hololeap basic web scraping katamari. browser automation selenium
<hololeap> yeah, I don't need anything like selenium for this. I want to log in to my router and log some stats every few seconds
<weaksauce> wait no nokogiri
<hololeap> mechanize uses nokogiri
ox1eef_ has joined #ruby
roadie has quit [Ping timeout: 248 seconds]
roadie has joined #ruby
infinityfye has quit [Quit: Leaving]
fat_shinobi has joined #ruby
<isene> Just discovered mruby. Before testing this myself, does anyone here know if my rsh would run with it - and if it would speed up rsh with a compiled execution file with embedded mruby?
roadie has quit [Ping timeout: 248 seconds]
ur5us has quit [Remote host closed the connection]
ur5us has joined #ruby
joto has quit [Remote host closed the connection]
joto has joined #ruby
huan has joined #ruby
<huan> uhm shouldn't this (1..16).inject([]) {|result, num| result.size} give me 0?
<leah2> no it fails?
<weaksauce> isene depends on what you need to do in your shell
<weaksauce> a lot of gems are incompatible with mruby
<isene> I have no gem dependencies...
<huan> leah2 it runs fine on my pc, it returns 8, I also put it in an online REPL and it gave me 4
<leah2> oh, it uses the size of the integer
<weaksauce> isene are you planning on requiring anything and using it?
<weaksauce> if not then yeah it would be faster and smaller footprint
<leah2> >> 16.size
<ruby[bot]> leah2: # => 8 (https://carc.in/#/r/f4nn)
<leah2> depends of you have a 32 or 64-bit machine
ur5us has quit [Ping timeout: 250 seconds]
<huan> ye ok i forgot
<huan> hahah
<isene> So, no. This kills it: Array does not support instance variables
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
<mooff> huan: it's that what you return in the block will be given as `result` for the next element
roadie has joined #ruby
<mooff> so the first time it receives your [], returns its .size
<huan> ye totally forgot that the last element is returned
<huan> i meant last expr
<mooff> that's 0. then it runs with the second item. 0.size => NoMethodError
<mooff> yeah
<mooff> sorry, missed leah's follow up :)
<huan> would have noticed it if the "sizeof" of an integer wasn't called size
<mooff> ah yeah, ffs
<leah2> ^^
shokohsc4 has joined #ruby
shokohsc has quit [Ping timeout: 268 seconds]
shokohsc4 is now known as shokohsc
roadie has quit [Ping timeout: 248 seconds]
roadie has joined #ruby
huan has quit [Quit: Client closed]
fat_shinobi has quit [Quit: Leaving]
roadie has quit [Ping timeout: 248 seconds]
<isene> Can Ruby be speeded up via some compilation?
kaivai has quit [Quit: ZNC - https://znc.in]
kaivai has joined #ruby
<mooff> isene: not massively for mruby. you're looking at startup improvements, mainly, in the realm of 5-10%
<weaksauce> isene what are you trying to optimize here?
<weaksauce> actual runtime speed or startup speed?
<weaksauce> truffleruby or jruby might be faster overall
<mooff> BUT that might be confabulation. i haven't measured it
<weaksauce> but not faster to startup
<mooff> mruby is a real nice sweet spot
<mooff> can run it on a Dreamcast
<mooff> it's very Japanese
<mooff> isene: don't worry about mruby compilation for now is my tip. it's not a jit
<isene> Ok
<mooff> your code totally can run on mruby btw
<mooff> it just might require slight modification
roadie has joined #ruby
roadie has quit [Ping timeout: 248 seconds]
roadie has joined #ruby
roadie has quit [Ping timeout: 248 seconds]