<xco>
i'm trying to return a hash based on the true values of another hash in some array
<xco>
i think i could use a #map here
<xco>
not sure how to manipulate it though
tau has joined #ruby
tau has joined #ruby
tau has quit [Changing host]
ur5us has joined #ruby
<adam12>
xco: reduce or each_with_object. Reduce being more classic and each_with_object maybe being a bit easier to get your feet wet with.
darkstardevx has quit [Ping timeout: 246 seconds]
imode has joined #ruby
<adam12>
xco: Could probably also use Enumerable#select here.
<xco>
adam12 i was thinking more along the lines of select and map in fact
<xco>
adam12 digging in usages of each_with_object too now
<xco>
into*
RingtailedFox has joined #ruby
<RingtailedFox>
hiya guys! can i install newer versions of Ruby for Windows on top of older ones, or do i need to uninstall them first?
Archenoth has quit [Quit: Leaving]
<RingtailedFox>
like, if i installed ruby to C:\Ruby-x64\ instead of C:\Ruby27-x64\.... would i be able to just plop a newer version on top of it?
darkstardev13 has joined #ruby
<adam12>
RingtailedFox: Should be fine? Only issue I foresee is the ruby in your PATH, if there is one.
<adam12>
xco: If you're on Ruby 2.7, hash.select { _2 }. Which looks absolutely magical but it's taking the second value to the block and selecting it if it's truthy.
<RingtailedFox>
yeah
bruce_lee has quit [Ping timeout: 260 seconds]
<RingtailedFox>
i just uninstalled both Ruby 2.6 and Ruby 2.5... i can fix the path if needed
bruce_lee has joined #ruby
bruce_lee has quit [Changing host]
bruce_lee has joined #ruby
<xco>
adam12 hash.select { _2 } looks too magical. i'll prefer the other methods
<adam12>
xco: hash.select {|_key, value| value } if you like verbosity :)
<adam12>
"verbosity"
<adam12>
xco: Lots of ways to approach this. Definitely explore each_with_object and/or reduce tho.
<leftylink>
I thought it wasn't to be based on the values of the same hash though
<xco>
adam12 hash.select {|_key, value| value } how's this supposed to work?
<xco>
adam12 when does the array come in?
<adam12>
Maybe I misunderstood?
<xco>
i think you did
<adam12>
Ah. I thought you just wanted hash -> result, with truthy values.
<xco>
i'm selecting bases on values from an array
<xco>
nooooo
<xco>
:D
<xco>
that would be too easy
<adam12>
My bad; it's been a long day :)
<xco>
adam12 yeah no worries
<leftylink>
I think I'd merge all elts of the array into one Hash[String => Boolean], and then I'd `hash.select { ... }` as appropriate
leitz has quit [Quit: Leaving]
<xco>
adam12 and i'd definitely avoid hash.select { _2 } for 1. too magical 2. not many people are on latest ruby versions
<leftylink>
could skip the merge and just do hash.select { array.find { ... }.values[0] } but I dislike unnecessary scan...
<xco>
leftylink hmmmm. that sounds legit. i thought it could be done on the fly without merging
<leftylink>
I guess that's OK if the scan time is acceptable!
<xco>
leftylink no go for the scan
<leftylink>
another way you can approach it, if the values in the array are guaranteed to be the same order as the kv pairs in the hash, is to zip, followed by... well, I'd say filter_map, but since you said you didn't want to rely on 2.7, then I guess you'd do map and compact
<xco>
leftylink i'm experimenting with your suggestions and learning along the way. sorry for the silence but it looks like zip is what i was missing which you suggested
<leftylink>
well, the reason I would be worried about that is because https://i.imgur.com/bf0ZlcD.jpg ("good grief. if you copy the homework, you learn nothing")
<leftylink>
I see
<leftylink>
well, I think we are good then
<leftylink>
leading to experimentation
<xco>
leftylink we're good! really good thank you. after applying zip i see how easy this is actually but i'm busy in the lab with all the other suggestions
<xco>
my explanation wasn't good enough so adam12 suggested things of how he understood my shitty explanation but then you too adam12 :D
<xco>
thank you too**
RingtailedFox has quit [Read error: Connection reset by peer]
jinmiaoluo has quit [Ping timeout: 258 seconds]
RingtailedFox has joined #ruby
dviola has quit [Ping timeout: 265 seconds]
gix has quit [Ping timeout: 258 seconds]
s2013 has joined #ruby
clemens3 has joined #ruby
Sina has quit [Quit: Connection closed for inactivity]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Rudd0 has quit [Read error: Connection reset by peer]
orbyt_ has joined #ruby
kinduff has quit [Read error: Connection reset by peer]
kinduff has joined #ruby
bga57 has joined #ruby
Arkantos has quit [Ping timeout: 258 seconds]
Rudd0 has joined #ruby
jinmiaoluo has joined #ruby
<havenwood>
xco: Where did `array` come from? An Array of Hashes like that is a bit awkward, which makes me want to just make it a Hash ASAP.
<havenwood>
xco: It's actually a bit easier to deal with if the `false` is `nil` in a Hash structure.
<xco>
havenwood i got that array from doing something like this YAML.load_file(File.join(__dir__, 'config.yml'))
<xco>
it's from a config yaml
<havenwood>
xco: gotcha
Arkantos has joined #ruby
<havenwood>
xco: Just some food for thought: array.reduce({}, :merge).merge(hash) { |_key, old, new| old && new }.transform_values { |value| value if value }.compact
<havenwood>
xco: I mean: array.reduce({}, :merge).merge(hash) { |_key, left, right| right if left }.transform_values { |value| value if value }.compact
<xco>
👀
<xco>
havenwood this one works nicely too.. thanks :)
cd has joined #ruby
<havenwood>
xco: Or consider: hash.slice(*array.map(&:to_a).map(&:first).filter_map { |key, value| key if value })
<xco>
havenwood this is also nice
<havenwood>
xco: With fewer loops: hash.slice(*array.filter_map { |h| h.to_a.first.then { |key, value| key if value } })
<havenwood>
xco: They Array of Hashes is just a bit awkward.
<havenwood>
The*
<xco>
havenwood i can understand that but awkard in this context or as a data structure?
<xco>
i believe you mean for our purpose here
<havenwood>
xco: As a data structure, just since it's both nested and a Hash is used as a Tuple.
<xco>
havenwood understand your point. i sort of read it as "Array of objects which is OK. the objects are Hashes"
<havenwood>
xco: It's often worth getting your data sorted first, as a threshold step.
<havenwood>
xco: Then you have to do fewer contortions down the line.
<xco>
havenwood won't that depend on the use case, the array is fixed size
CrazyEddy has quit [Remote host closed the connection]
<havenwood>
xco: Here, for example, I just mean first process `array` to get the keys. Extract that step to a method.
<xco>
plus the order is important here
<havenwood>
xco: I'm saying consider breaking the problem down to:
<havenwood>
I have: [{"car"=>true}, {"house"=>false}, {"pet"=>true}]
<havenwood>
I want: ["car", "pet"]
<xco>
oh i get it
<xco>
havenwood then using ["car", "pet"] i can select them from the hash as keys
<xco>
havenwood is that what you mean?
<havenwood>
xco: Yup: hash.slice(*keys)
<xco>
havenwood hm. this is a way better way of thinking around the problem
<havenwood>
&>> [{"car"=>true}, {"house"=>false}, {"pet"=>true}].reduce(:merge).filter_map { |key, value| key if value }
<erpel>
heyho - I'm publishing a gem that needs eventmachine with tls but if people don't have openssl headers installed on their machine when they do 'gem install mygem' they can't use the software. Is there a way to make dependencies indicate something is missing earlier than when running my software for the first time?
akem has joined #ruby
akem has quit [Max SendQ exceeded]
akem has joined #ruby
cnsvc_ has joined #ruby
TzilTzal has joined #ruby
cnsvc_ has quit [Ping timeout: 240 seconds]
darkstardev13 has quit [Remote host closed the connection]
<Manchotix[m]>
<erpel "heyho - I'm publishing a gem tha"> Heyho maybe you can check gem like mysql or the ruby gem for postgresql. This gem need the db-client libs install on the system otherwise the installation will break. Maybe you can to it in the same way.... something like please install the openssl-head files and check this if people install your gem. but is only my first idea to that :)
<Manchotix[m]>
> <@freenode_erpel:matrix.org> heyho - I'm publishing a gem that needs eventmachine with tls but if people don't have openssl headers installed on their machine when they do 'gem install mygem' they can't use the software. Is there a way to make dependencies indicate something is missing earlier than when running my software for the first time?
<Manchotix[m]>
* Heyho maybe you can check gem like mysql or the ruby gem for postgresql. This gem need the db-client libs install on the system otherwise the installation will break. Maybe you can do it in the same way.... something like please install the openssl-head files and check this if people install your gem. but is only my first idea to that :)
<erpel>
Manchotix[m] that sounds like a great resource to look at, thanks for thinking about it
<Manchotix[m]>
<erpel "Manchotix that sounds like a gre"> no problem :)
jenrzzz has quit [Ping timeout: 258 seconds]
conta has quit [Quit: conta]
RingtailedFox has quit [Read error: Connection reset by peer]
RingtailedFox has joined #ruby
jenrzzz has joined #ruby
BH23 has quit [Quit: Leaving]
BH23 has joined #ruby
ur5us has joined #ruby
Emmanuel_Chanel has quit [Ping timeout: 246 seconds]
jokester has quit [Ping timeout: 272 seconds]
Rudd0 has joined #ruby
Arahael has joined #ruby
Emmanuel_Chanel has joined #ruby
ur5us has quit [Ping timeout: 260 seconds]
InfosecTai has joined #ruby
<InfosecTai>
join #perl
<RingtailedFox>
hrm, i'm having an odd issue now....ERROR: While executing gem ... (Errno::EACCES)
<RingtailedFox>
Permission denied @ rb_sysopen in C:\users\user\.gem\specs\rubygems.org%443\Marshal.4.8\
AndreYuhai has joined #ruby
greengriminal has quit [Quit: Leaving]
jinmiaoluo has quit [Ping timeout: 240 seconds]
jinmiaoluo has joined #ruby
vondruch has quit [Ping timeout: 256 seconds]
<AndreYuhai>
Hey there, so I was trying to write an API wrapper by reading another one on Github. So the website basically has topics and entries. When I send a request to either 'api../topic' or 'api../entry' both return the same structured response. The difference is one has only one entry and the one has multiple (since it's a topic request)
<AndreYuhai>
So I am confused as to how to implement this. I have two classes called entry and topic.
<AndreYuhai>
I also tried to explain in detail in one of the links.
<AndreYuhai>
I want something like client.entry(entry_id) to return an entry. But that entry should also have topic details. But in the api response topic details always come first and then inside there is a variable called entries.
<AndreYuhai>
I want entry to have topic as well so the user can simply do entry.topic.title or something like this.
jenrzzz has quit [Ping timeout: 260 seconds]
<RingtailedFox>
no matter what i do, i keep getting this error: ERROR: While executing gem ... (Errno::EACCES)
<jackal>
if its fixed in the source, maybe i should wait debian port to be fixed?
tastemakerChuck has joined #ruby
<adam12>
jackal: Maybe. Is this affecting anything else?
<adam12>
jackal: You could try an older version, using the same steps I mentioned.
<jackal>
no idea if it affects anything
<jackal>
i came in here asking when i got the error
<jackal>
havent tried any project using ruby
<jhass>
jackal: is the 3.1.3 from debian or from a prior gem update --system?
<jackal>
gem
<jackal>
or maybe something conflicts with debian port
cliluw has quit [Quit: Leaving]
TomyWork has quit [Remote host closed the connection]
ellcs1 has joined #ruby
TzilTzal has quit [Quit: Leaving.]
<jhass>
jackal: I'd try downgrading by reinstalling the debian package then
<jhass>
do they still split ruby and rubygems into two packages? both to be sure
<jhass>
and then upgrading again from the downgraded version
<RingtailedFox>
adam12, it keeps whining about permissions errors when i try to run thigns like gem install... or even uninstalling it via control panel.. have to run the uninstaller as admin
cliluw has joined #ruby
orbyt_ has joined #ruby
tf2ftw has joined #ruby
plutes has joined #ruby
linetrace has joined #ruby
<adam12>
RingtailedFox: Can you install to non-Program Files directory as non-admin?
<RingtailedFox>
yes. i was trying to install ruby to C:\Ruby-x64 (it usually defaults to C:\Ruby27-x64)
<adam12>
RingtailedFox: And once you do that, `C:\Ruby-x264\bin\gem install somegem` gives you a permissions error?
<RingtailedFox>
i had ruby 2.6 installed a few weeks back but got rid of it.... trying to install 2.7 now but it's just been a headache... i forget which exact version i had previously
<RingtailedFox>
well, here's the thing: ruby isn't installed right now. should i install it as admin, or non-admin?
<adam12>
I'm not sure to be honest, but I'd say prefer install as non-admin, at least for now.
<adam12>
I run Windows but use WSL religiously, so I dont' have a ton of experience with the RubyInstaller version.
<RingtailedFox>
yes, i can, though i was hoping to wait until the May 2020 update is approved for my laptop, then i'd upgrade to WSL 2
<havenwood>
RingtailedFox: Ah, gotcha.
<RingtailedFox>
what's the difference between RubyOnRails and RubyInstaller?
jinmiaoluo has quit [Ping timeout: 272 seconds]
<RingtailedFox>
i'm running an ASUS ROG laptop... just wanna make sure it's compatible with the update so i don't have to spend a few days/weeks re-installing all my steam games :p
<havenwood>
RingtailedFox: RubyInstaller is a Windows-specific tool for installing Ruby. Ruby on Rails is the most popular web framework for the Ruby language.
gerep has joined #ruby
<RingtailedFox>
ahhh ok
<havenwood>
RingtailedFox: RubyInstaller with DevKit should be fine for getting Ruby nominally working in Windows without WSL.
<havenwood>
RingtailedFox: Or you can install via Chocolatey.
<gerep>
Hello humans. I am trying to understand one thing about modules. I know what it does but I am reading this code https://github.com/slack-ruby/slack-ruby-bot/blob/master/TUTORIAL.md#application and trying to understand what is happening when I declare a module "SlackMathbot" in two different files, in runtime they get merged or something?
<havenwood>
gerep: It reopens the module.
<havenwood>
gerep: You can do that with both modules and classes.
<gerep>
havenwood, and the `require` order is important?
<havenwood>
gerep: Even at runtime, you can reopen a module and define new methods or redefine a method.
<havenwood>
gerep: The require order is important if one is stomping on the other.
<adam12>
2.7.1 in available via scoop too.
<miskatonic>
there are people who pretend obstinately that rails and similar frameworks is the one and only reason to use Ruby
<RingtailedFox>
chocolatey is obsessed with shoving Ruby into C:\Tools\Ruby, though
<RingtailedFox>
and i don't want it there becuase i already have some tools in there and want to keep ruby seperate (preferrably in C:\Ruby-x64)
<gerep>
havenwood, another question. What happens to the class defined inside the module? My understanding of modules is that I can create methods to reuse in different classes. I can do this by including the module in my class definition.
<gerep>
I would I create a class inside a module?
<gerep>
*why
<havenwood>
gerep: Namespaces are just namespaces, nothing more. By defining a class inside a module, you give it a namespace.
<jackal>
adam12, jhass, reinstalling debian and updating via gem later produces same error
<havenwood>
gerep: Nothing else special happens.
<jackal>
i guess i'll wait for debian/ruby fix
<jhass>
might be best, yeah
<gerep>
havenwood, so I cannot create an instance of a class inside a module?
<jhass>
or just sidestep debian and use a ruby version manager like 80-90% of rubyists and probably 98% on debian
bga57 has quit [Ping timeout: 246 seconds]
m27frogy has quit [Ping timeout: 265 seconds]
greengriminal has quit [Quit: This computer has gone to sleep]
<jhass>
gerep: yes you can for every possible interpretation of that I can come up with :)
<RingtailedFox>
is there a way to tell chocolatey "no, you install it in C:\Ruby-x64\"?
greengriminal has joined #ruby
bga57 has joined #ruby
<RingtailedFox>
attempting with choco install ruby --params "/InstallDir:C:\Ruby-x64"
<jhass>
gerep: no, the module is just acting as namespace here
<RingtailedFox>
do i need the MSYS crap too?
<gerep>
jhass, and why is that required?
<gerep>
I need to read more about namespaces hahaha
<jhass>
gerep: it's not required, it just serves code organization. Bot is very generic name, if everybody would use the toplevel for everything it would likely conflict with something else
<gerep>
Ah!!!!!
<gerep>
Makes sense now jhass =)
<RingtailedFox>
havenwood: got ruby installed now..... just, it seems to not like running anymore :P
<RingtailedFox>
adam12, got ruby installed, though chocolatey seemed to have a conniption about it until i ran it as admin :P
<gerep>
jhass, still testing your patience....the module class "Bot < SlackRubyBot::Bot" is probably used by the "SlackRubyBot" library and it is called in the Config.ru file. This file is calling "SlackMathbot::Bot.run", is that a call to the Bot class inside the "SlackMathbot" module?
<jhass>
gerep: yes, :: here accesses the namespace
<jhass>
in fact you could rewrite module A; class B; to module A; end; class A::B; end;
<gerep>
jhass, cool! And when I have a module inside a module, I believe it serves the same purpouse you said before, code organization. If that is the case, the method inside a "sub-module" is available for the "parent" module?
<gerep>
jhass, nice! That explanation about the rewrite clears my doubt about examples I have found where a class was defined outside the module.
<RingtailedFox>
really.... i have to install gems as admin.... *sighs*
jenrzzz has joined #ruby
<RingtailedFox>
is this normal behaviour for ruby installed via chocolatey?
<jhass>
gerep: module's have dual use in Ruby, as namespaces like we talked about, but also to share functionality among classes. So a module within module can server to further organize the code as you say, or to collect some methods to be shared by multiple classes. Or both. A class does not inherit the methods a module defines unless it calls include TheModule; Where it's defined in scope makes no
<jhass>
difference for this
<adam12>
RingtailedFox: Afraid I don't know, but if you installed Ruby by Admin, then in theory gems would be as well. There's methods around that, such as --user-install and setting GEM_HOME environment variable.
<RingtailedFox>
i installed ruby via chocolatey... and chocolatey seems to hate running as user and NOT admin...
<gerep>
jhass, you shine in the darkness my friend, thank you so much for your time!
<jhass>
yw :)
<RingtailedFox>
i love the ability to update via choco, though
jenrzzz has quit [Ping timeout: 256 seconds]
TCZ has joined #ruby
davispuh has joined #ruby
chalkmonster has quit [Quit: WeeChat 2.8]
alexherbo24 has joined #ruby
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo24 is now known as alexherbo2
chalkmonster has joined #ruby
<havenwood>
RingtailedFox: Typically if a package manager chooses a system location for gems, you can just move the gem location.
<havenwood>
RingtailedFox: That way Ruby can still be updated by the package manager, but gems install into a local directory that you have permissions for.
<havenwood>
RingtailedFox: It's *where* gems are installed that matters.
<havenwood>
RingtailedFox: There's a default `gem env gemhome` but like adam12 mentioned, you can move that install directory anywhere you want.
<havenwood>
RingtailedFox: All you need to do other than setting GEM_HOME or using --user-install flag (with command or in .gemrc) is to add the new `gem env gemhome`/bin to your PATH.
<havenwood>
RingtailedFox: TL;DR: Install gems wherever you want and add the $GEM_HOME/bin to your $PATH.
gerep has quit [Quit: Leaving]
tvw has joined #ruby
m27frogy has joined #ruby
<RingtailedFox>
gem install whines about permissions whenever i install ruby as admin... unless i run the command prompt as admin
<RingtailedFox>
i just find it all very strange
fercell has quit [Quit: WeeChat 2.8]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jetchisel has joined #ruby
RingtailedFox has quit [Read error: Connection reset by peer]
RingtailedFox has joined #ruby
jenrzzz has joined #ruby
banisterfiend has quit [Quit: banisterfiend]
jenrzzz has quit [Ping timeout: 264 seconds]
jenrzzz has joined #ruby
Jonopoly has quit [Quit: WeeChat 2.8]
TCZ has quit [Quit: Leaving]
orbyt_ has joined #ruby
houhoulis has joined #ruby
segy_ has joined #ruby
segy has quit [Ping timeout: 265 seconds]
segy_ is now known as segy
ur5us has joined #ruby
Archenoth has quit [Quit: Leaving]
kinduff has quit [Read error: Connection reset by peer]
kinduff has joined #ruby
r29v has joined #ruby
miskatonic has quit [Quit: ERC (IRC client for Emacs 24.5.1)]
<RingtailedFox>
The last version of nokogiri (>= 0) to support your Ruby & RubyGems was 1.10.9. Try installing it with `gem install nokogiri -v 1.10.9`
<RingtailedFox>
nokogiri requires Ruby version >= 2.3, < 2.7.dev. The current ruby version is 2.7.1.83.
<RingtailedFox>
ERROR: Error installing nokogiri:
<apotheon>
What version of Ruby and RubyGems are you using?
<xco>
the whole code is a mess, i'm very tired today so extra comments welcome
lesha__ has joined #ruby
<apotheon>
Oh, I totally missed the "current ruby version is 2.7.1.83" part, somehow.
<apotheon>
Okay, yeah, that's weird. I blame Microsoft.
lesha_ has quit [Ping timeout: 256 seconds]
<RingtailedFox>
2.7 for windows x64
<RingtailedFox>
ruby version if 2.7.1.83
<RingtailedFox>
rubygems is... how do i find THAT out
<RingtailedFox>
ahh gem -v
<apotheon>
gem -v
<apotheon>
oh, too slow
<RingtailedFox>
yeah, sorry. nearly passed out in the heat twice today, so please forgive me from being completely braindead
<apotheon>
no . . . it's fine
<RingtailedFox>
sorry jsut waiting for choco to finish installing msys2
<apotheon>
Stuff happens, people forget things. It happens to me all the time.
<RingtailedFox>
yeah, had to haul a bunch-o-crap to the city dump today... was doing that from... 8 AM local time until an hour ago
<apotheon>
I wish I had a clue. I've never used Ruby on Windows.
<RingtailedFox>
i have but it's... a chore :p
<RingtailedFox>
this is the first time for me installing it via chocolatey though
<apotheon>
interesting
<RingtailedFox>
eyah
<RingtailedFox>
RubyGems version: 3.1.2
<apotheon>
It seems like nokogiri should install just fine. I don't know what's up.
ur5us has joined #ruby
NGC3982 has quit [Ping timeout: 258 seconds]
<RingtailedFox>
yeah, i kinda need nokogiri installed... otherwise it kinda defeats the purpose of Ruby....
<apotheon>
hmm
<apotheon>
Maybe you should try a different OS. That is, unfortunately, the best advice I have at the moment.
<RingtailedFox>
it gives that error no matter what version i ask for... if i tell it to install nokogiri 1.8.5, it says "the last version to support ya was 1.8.5, so try installing that"
<RingtailedFox>
ugh
<RingtailedFox>
i can't use another OS
<apotheon>
I haven't used Widnows for a very, very long time.
<apotheon>
. . . so I'm going to be zero help to you now.
<RingtailedFox>
its ok
<RingtailedFox>
you still helped me a bit
<apotheon>
I'm assuming you did some web searching.
<apotheon>
I'm guessing something like WSFL (or whatever it's called) or a VM won't help you.
<apotheon>
Isn't there a version manager for Ruby that runs on Windows?
<apotheon>
Pik? Is that it?
<RingtailedFox>
i have no idea
<RingtailedFox>
i have WSL
<RingtailedFox>
but... i'm waiting for the May 2020 update to become available for my laptop so i can upgrade it to WSL 2
<apotheon>
WSL, that must be it. Is there some way to install via WSL?
<apotheon>
Windows Subsystem for Linux?
<RingtailedFox>
i'm sure tehre is
<RingtailedFox>
wut
<RingtailedFox>
WUT
jenrzzz has joined #ruby
<RingtailedFox>
gem install nokogiri --pre succeeded in installing 1.11.0.rc2
<apotheon>
I see.
plutes has quit [Read error: Connection reset by peer]
<apotheon>
That's a bit odd.
<RingtailedFox>
yeah but if it works, i'll take it :P
<apotheon>
Why would it allow a pre-release, but fail on everything else?
<apotheon>
Good luck!
<apotheon>
I'm glad you found something that works.
<RingtailedFox>
yeah me too
<RingtailedFox>
i have no idea
<RingtailedFox>
i'll try to walk my way back with previous versions sinc eruby allows for multiple versions of gems