<NL3limin4t0r>
hramrach: I wouldn't find it weird. I've worked with sockets in C and you tippically split of a new thread to handle the incomming connection, then close the socket on the main thread and listen for incomming connections again. So the file descripor should be availble on the main thread again.
akemhp_ has quit [Ping timeout: 240 seconds]
feep[work] has joined #ruby
<feep[work]>
hi
<feep[work]>
why does rubocop ignore files listed on the commandline if they don't have a ruby extension?
<feep[work]>
like, if I specifically give you the file, it stands to reason that should override filters?
<feep[work]>
repro: touch foo; rubocop foo
<feep[work]>
background: I can't lint rakefile
<feep[work]>
Include doesn't work either
<hramrach>
NL3limin4t0r: if you don't take care to pass the fd as block argument it is teh same in concurrent threads
<hramrach>
as in Ruby loops don't have own scope so you get same scope for each iteration of the accept loop and the update of the fd in the accept loop applies to all threads that reference the fd from the accept loop local scope
akemhp has joined #ruby
<feep[work]>
found a workaround: #!/usr/bin/rake at the top of rakefile
<feep[work]>
bit hacky
<feep[work]>
I still want to know why rubocop ignores it otherwise.
Tuor has joined #ruby
william1_ has joined #ruby
<Tuor>
Hi I just installed rbenv and wanted to install ruby 2.7.0 but it's not available. I'm running kubuntu 19.10 and did install rbenv with apt.
Lyubo1 has quit [Ping timeout: 240 seconds]
Jonopoly has joined #ruby
phaul has quit [Ping timeout: 260 seconds]
<Tuor>
I think it's because it's an old version of rbenv.
<leftylink>
speaking of Ruby 2.7... does carcinogen have that yet?
<feep[work]>
while we're at it, wtf is up with Style/ClassVars?
<feep[work]>
it's a linter error that's like ... "this ruby feature, doing exactly what it's supposed to, is 'bad' because we don't trust you to understand what it does"
<feep[work]>
a linter should not be a tool for backdoor language design.
<feep[work]>
oh well, another cop to disable
<ytti>
linter should be opinionated
<ytti>
the goal should be to have one answer to every question and enforce that answer
<ytti>
the utility of having same thing same way always is significnat
<feep[work]>
yes, but the question should not be "should ruby be designed the way it is"
<feep[work]>
and the answer should not be "no"
<feep[work]>
there is a process for that, it's called deprecation
<ytti>
lot of linters are opinionated about language features
<ytti>
and do not allow specific language features
<feep[work]>
sure, for basically-unmaintained languages
<feep[work]>
like C
<ytti>
black does that for python
<feep[work]>
where releases are yearly and require a committee
<ytti>
'we dont like it, because we dont like it'
<ytti>
and i'm fine by that
<ytti>
gofmt does that for go
<ytti>
i think being highly opinionated is good, not bad
<feep[work]>
I think it's bad there too
<feep[work]>
nothing wrong with being opinionated, I just think it's the wrong forum
<ytti>
it's foru mwhere they can implement the change NOW
<feep[work]>
the forum for being opinionated about language design is the language's dev ml.
<ytti>
that may never happen
<feep[work]>
then it shouldn't happen in the linter either.
<ytti>
in the mean time, your project has different opinions on same problem
<ytti>
i personally want the linter to decide on competing language features which one is the right one
<feep[work]>
yes, but those are not competing language features!
<feep[work]>
this is a language feature, that was decided to be in the language, and is not scheduled for deprecation
<feep[work]>
and there's a cop that says "this entire feature is bad, remove"
<feep[work]>
and it's *on by default*
<feep[work]>
this is broken.
<ytti>
i for one agree
<ytti>
if you need @@ it's almost always wrong
<ytti>
if it's not wrong, add exception for _that_ line
<feep[work]>
I mean, what I'll actually do is turn the cop off, but ... why is that wrong?
<ytti>
there is no wrong or right, just what people prefer
<ytti>
you prefer on thing
<NL3limin4t0r>
Both a class instance variable and a class variable have their own use cases. However if you're not familiar with a class variable in Ruby the class instance variable is the safer option, that is why it's recommended by RuboCop.
<ytti>
i prefer the thing it does
<feep[work]>
you said "it's almost always wrong" so why is it wrong?
<feep[work]>
NL3limin4t0r: but ... they don't solve the same problem...
<ytti>
i'd need to see the code
<ytti>
to say if in that case it 's needed or not
<ytti>
but in most cases, there is cleaner solution to the problem, where they are not needed
<ytti>
in some cases, the cleanest solution available uses them
<feep[work]>
okay, I hope so, so I'll just ask for the cleaner solution
<feep[work]>
what we basically want is a namespace, ie. a class with just static methods
<NL3limin4t0r>
They dont solve the same problem, but there is a lot of overlap.
<feep[work]>
it's never inherited and never instantiated
<ytti>
usually people use module for namespace (and include that when needed)
<feep[work]>
right, but I want to write Foo.method()
<feep[work]>
can I do that with module?
<ytti>
yes
<feep[work]>
okay, then nevermind the whole topic :DD
<feep[work]>
yeah but ... this is just bad language design imo
<feep[work]>
I don't want to even leave the option to instantiate it
<feep[work]>
you shouldn't have to rely on discipline to get correct behavior
<feep[work]>
in that sense, module seems perfect
<feep[work]>
thanks NL3limin4t0r!
<ytti>
if you share that code with people familiar with ruby, they won't like it
<feep[work]>
ytti for debate too :)
<NL3limin4t0r>
You can't instantiate a module, but a module is an instance itself if that makes sence.
<feep[work]>
NL3limin4t0r: that makes perfect sense
<ytti>
but at least we covered 'usually more idiomatic solution than using @@var'
<ytti>
since while this is not what i'd do, it's still more idiomatic than original
Omnilord has quit [Quit: Leaving]
<NL3limin4t0r>
I guess in your usecase the differnces between @@var and @var isn't terribly noticable, since you only use the module as namespace for "module function". But mostly an instance variable @var is what you want, there are reasons to use @@var but you first have to know where they differ.
<feep[work]>
I mean, that goes for every nontrivial language feature, right?
<feep[work]>
I don't think we should be so afraid of noobs using the wrong feature that we sacrifice the capacity
<NL3limin4t0r>
However if your module where to be included in a class you might notice some differnces.
<NL3limin4t0r>
But I guess ^ isn't the intent of your module
phaul has joined #ruby
<feep[work]>
yep
Lyubo1 has joined #ruby
howdoi has quit [Quit: Connection closed for inactivity]
<NL3limin4t0r>
if your variable is a constant you should use SOME_CONSTANT like ytti suggested
<maloik>
Hey folks. Not strictly a ruby question, but I'm wondering if anyone has any tips for technology and/or services that would be able to identify climbing holds on a picture of a climbing wall
<emilych>
it works but if you find something odd I'd be glad to improve the code
akemhp has quit [Remote host closed the connection]
akemhp has joined #ruby
alexherbo2 has joined #ruby
bsdbandit-01 has joined #ruby
akemhp has quit [Ping timeout: 268 seconds]
lunarkitty has quit [Ping timeout: 260 seconds]
alex`` has joined #ruby
lunarkitty has joined #ruby
phaul has quit [Ping timeout: 265 seconds]
<emilych>
2.6.3 (main):0 > file = File.open("final_result.json");new_hash = JSON.parse(file) TypeError: no implicit conversion of File into String
<emilych>
how can I fix this?
<emilych>
ah, i found the solution
<NL3limin4t0r>
data = JSON.parse(File.read('final_result.json'))
<emilych>
yes, thanks!
snappy has joined #ruby
<NL3limin4t0r>
`File.read('final_result.json')` directly returns a string while File.open will return a file that you still have to read from (and close if you don't use a block).
<snappy>
q: i'm running 'test do system bin/"dsvpn", "--help"' for homebrew, is htere a way to check the return is value 254?
<feep[work]>
man, given a new rubocop cop it
<feep[work]>
's about 50/50 if I end up following it or turning it off permanently
<feep[work]>
that's not a good ratio
phaul has joined #ruby
<feep[work]>
(turned off so far: AbcSize, BlockLength, BlockNesting, MethodLength, HeredocDelimiterNaming, AndOr, Not, ClassVars, ConditionalAssignment, FrozenStringLiteralComment, HashSyntax, LineEndConcatenation, MutableConstant
<feep[work]>
)
<feep[work]>
and like, that's not "I don't want to bother fixing this", it's "what on earth where they thinking"
<feep[work]>
were*
<NL3limin4t0r>
RuboCop comes with defaults, but should be configured to your own liking
<feep[work]>
right, which is so far mostly taking the form of turning off parts of it...
<NL3limin4t0r>
configure the settings you don't like
<feep[work]>
right, I'm doing that
<feep[work]>
I'm just griping, ignore me
AJA4350 has joined #ruby
<NL3limin4t0r>
emilych: there is quite a lot that can be improved, for example your method `transform_to_array` merges the `month` and `doc_count` into a string. I would keep the data seperated as long as possible until there is the need to merge it. Keeping it seperated would for example make it way easyier to check if a month is already present.
davispuh has quit [Read error: Connection reset by peer]
x0n has joined #ruby
DTZUZO_ has quit [Read error: Connection reset by peer]
DTZUZO_ has joined #ruby
chalkmonster has joined #ruby
davispuh has joined #ruby
akemhp has joined #ruby
ellcs has quit [Remote host closed the connection]
ellcs has joined #ruby
maloik has quit [Ping timeout: 260 seconds]
fphilipe has joined #ruby
voker57 has quit [Quit: voker57]
hays has joined #ruby
hays has quit [Client Quit]
juvenal has joined #ruby
tsujp has joined #ruby
<emilych>
Hi, I have this array and like to remove the datestamp in all elements: m = %w[2019-01-01T00:00:00.000Z 2019-02-01T00:00:00.000Z: 2019-03-01T00:00:00.000Z:\ 12341234 ]
<feep[work]>
okay, here's another super weird question
<feep[work]>
I have a config file that contains some eval strings that do some stuff
<feep[work]>
I want the eval strings to be able to call some functions with foo(), I want those functions to have access to some local context, but I also need global definitions made in the eval block to be inserted into the global namespace
<feep[work]>
and preferably I want to do this without defining any global variables myself, currently I use a temporary which is ugly
<feep[work]>
temporary global*
<feep[work]>
I can't use lambda because then it's foo.call(), not foo()
<feep[work]>
I can't eval in a class context because then the globals will land in the class, not the surroundings
rapha has left #ruby ["WeeChat 2.3"]
anveo has joined #ruby
<feep[work]>
alternately, is there any way to let me call a proc as a method
<feep[work]>
ie. with foo()
lucasb has joined #ruby
<feep[work]>
may have found a way!
jcalla has joined #ruby
<feep[work]>
haha yes, eval inside instance_eval
<feep[work]>
FOO = "bla" goes to the surrounding namespace, but you can call methods as if you're in the class
turbo_choo has joined #ruby
chalkmonster has quit [Remote host closed the connection]
fuzzface has joined #ruby
impermanence has joined #ruby
juvenal has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<NL3limin4t0r>
I'm not entirely sure if I've got the output you want though
<emilych>
OHHH, wow! My head is exploding!
<emilych>
cool, you reduced my script to half and it's much clearer and more robust! thank you very much!
<emilych>
third= one third
<NL3limin4t0r>
np, I currently wrote it in plain script form, but you can hang it in a class or module if you want. possibly extracting some logic into private methods
<emilych>
not half even to one third
<emilych>
yes, I'll do! thanks again!
<feep[work]>
hm
<feep[work]>
is this intended to work? ie. may this get broken by a future ruby update?
<NL3limin4t0r>
I've also opted use OpenStruct as object class for JSON parsing, since that allows you to navigate the objects using dot syntax (`object.attribute`) which makes mapping attributes a lot cleaner (`array.map(&:attribute)` instead of `array.map { |object| object['attribute'] }`).
<feep[work]>
ie. blocks evaluated in classes with instance_eval still being able to set global constants
<emilych>
cool! I read some time ago about openstruct, good to see an use case in my example!
Swyper has joined #ruby
drincruz_ has joined #ruby
<NL3limin4t0r>
feep[work]: Why use an eval string? Can't you use a proc instead, that you invoke at the point you need it? Is it serialized from a yml/json file, because that's a valid reason you can't use a proc.
<ellcs>
NL3limin4t0r: when using ostruct, dont you have performance considerations?
juvenal has joined #ruby
juvenal has quit [Client Quit]
<feep[work]>
NL3limin4t0r: because we didn't understand how procs worked when we wrote allllll this config, and now we're stuck with it :D
william1_ has joined #ruby
<feep[work]>
(also because we want to inject variables into it)
craz has joined #ruby
<feep[work]>
are there better ways? yes. definitely, yes.
<feep[work]>
not worth the effort of switching tho
Swyper has quit [Remote host closed the connection]
<NL3limin4t0r>
ellcs: I haven't taken performence into account. It might be a bit slower, but imo way more readable.
Swyper has joined #ruby
<NL3limin4t0r>
ellcs: Performence only matters at the point that it's actively hindering you. Otherwise I would go over readability 95% of the times.
Swyper has quit [Remote host closed the connection]
<NL3limin4t0r>
Since I don't know how large the api response is going to be I use OpenStruct, since most apis limit the response to a certain number that leaves quite a lot of margin before throtteling. If an array of 10k elments is returned you might start noticing some issues.
sergioro has joined #ruby
<NL3limin4t0r>
feep[work]: So basically you have some legacy strings that must be evaluated.
<feep[work]>
yep
gheegh has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Jonopoly has quit [Quit: WeeChat 2.5]
Swyper has joined #ruby
<NL3limin4t0r>
You can dynamically create methods and pass them a proc. Say you have a proc `foo = proc { ... }` you can define a method `foo` by using `define_method(:foo, &foo)` or `define_singleton_method(:foo, &foo)` depending on your context. Note that if you `eval` your string while the variable `foo` is still in scope "foo()" will refer to the method, but "foo" will refer to the variable.
<feep[work]>
right but it also can't be a method
<feep[work]>
that's the hilarious part
<feep[work]>
cause it has to also be able to define global variables
<feep[work]>
non-class-namespaced global variables
<ellcs>
couldn't resist and wrote a small benchmark. the only situation i would avoid using ostruct, is when setting values `o.b = 2`.
<NL3limin4t0r>
you can define global variables from within a method
<feep[work]>
NL3limin4t0r: yes but they're namespaced to the class
<feep[work]>
owait
<feep[work]>
NL3limin4t0r: I understand what you mean
<feep[work]>
this is coool
<feep[work]>
that might be the much easier way
andikr has quit [Remote host closed the connection]
<NL3limin4t0r>
global variables are defined with a dollar sign at the front
<NL3limin4t0r>
`$foo` would be global
<feep[work]>
I mean allcaps globals, .... constants?
<NL3limin4t0r>
and is accessible everywhere in the program
<feep[work]>
NL3limin4t0r: yep, define_method did it, thanks a bunch
<feep[work]>
hm
<feep[work]>
NL3limin4t0r: hm
<feep[work]>
though
dionysus69 has quit [Quit: dionysus69]
<feep[work]>
if I do this in a loop in a module, won't the defined methods be global?
<NL3limin4t0r>
ellcs: the JSON library uses os['attribute'] = 'value' to set all propperties in `JSON.parse(json, object_class: OpenStruct)`
ste512 has joined #ruby
<NL3limin4t0r>
feep[work]: Correct, the methods aren't global.
<NL3limin4t0r>
To define global methods you should define them on Kernel.
<NL3limin4t0r>
those are avaible everywhere (except in BasicObject)