Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 09 11:32
    straight-shoota labeled #7306
  • Aug 09 11:32
    straight-shoota labeled #7306
  • Aug 09 11:30
    straight-shoota closed #12370
  • Aug 09 11:30
    straight-shoota labeled #12370
  • Aug 09 11:30
    straight-shoota labeled #12370
  • Aug 09 11:30
    straight-shoota unlabeled #12370
  • Aug 09 03:30
    orangeSi synchronize #12356
  • Aug 09 01:23
    cyangle synchronize #12355
  • Aug 09 01:10
    cyangle synchronize #12355
  • Aug 09 00:58
    refi64 synchronize #12367
  • Aug 08 23:33
    decademoon labeled #12370
  • Aug 08 23:33
    decademoon opened #12370
  • Aug 08 16:30
    kalinon opened #12369
  • Aug 08 16:30
    kalinon labeled #12369
  • Aug 08 09:37
    HertzDevil edited #12366
  • Aug 08 08:32
    orangeSi synchronize #12356
  • Aug 08 08:10
    orangeSi synchronize #12356
  • Aug 07 22:57
    HertzDevil edited #12368
  • Aug 07 22:57
    HertzDevil labeled #12368
  • Aug 07 22:57
    HertzDevil labeled #12368
George Dietrich
@Blacksmoke16
https://github.com/crystal-lang/crystal/issues/2661#issuecomment-877286921 is prob similar to what's going on ^ if i had to guess
Jason Waldrip
@jwaldrip
Which is strange... the return type method ensures the proper type is returned
or at least it should
George Dietrich
@Blacksmoke16
but you're doing a .as(Psykube::Generator::Podable::Resource)
where Resource is an alias to a union of other types
Jason Waldrip
@jwaldrip
so really I would have to case over each type in the union to get what I want
George Dietrich
@Blacksmoke16
or make use of overloads for specific types
Jason Waldrip
@jwaldrip
ya, let me see what I can do
Alex Kampa
@alex-kampa
Now here's a bit of a surprise:
puts [1, 2, 3, 4, 5].reduce(0) { |acc, i| acc = acc + 1 if i.to_s =~ /3/ }
Error: undefined method '+' for Nil (compile-time type is (Int32 | Nil))
George Dietrich
@Blacksmoke16
i think you need some parans
parens*
i think the if is making the type of acc possibly nil, because the return value of the block is used to set the acc
.reduce(0) { |acc, i| i.to_s =~ /3/ ? acc + i : acc }
is 3 the expected value here?
From IRC (bridge bot)
@FromIRC
<mfiano> Can someone ELI5 the ~> version operator?
George Dietrich
@Blacksmoke16
image.png
From IRC (bridge bot)
@FromIRC
<mfiano> I read that
<mfiano> Maybe I'm dumb
George Dietrich
@Blacksmoke16
afaik its the same as the ^ in other langs
From IRC (bridge bot)
@FromIRC
<riza> mfiano: the idea with ~> is that it allows for upgrades within the specified point but no higher
George Dietrich
@Blacksmoke16
just a shortcut to say allow versions within this range
From IRC (bridge bot)
@FromIRC
<riza> so if you ~> x.y.z, you leave room for z to increment but not y
George Dietrich
@Blacksmoke16
^
From IRC (bridge bot)
@FromIRC
<riza> and if you ~> x.y, y can increment, z can be anythnig and x cannot change
<mfiano> Oh very good. I don't see why you would want to leave room for y or x to upgrade...how can you know anything other than a patch won't break your code?
<riza> its used under the assumption that the project you're referencing follow SemVer
Alex Kampa
@alex-kampa

Thanks @Blacksmoke16 your solution works, even though

puts [1, 2, 3, 4, 5].reduce(0) { |acc, i| i.to_s =~ /3/ ? acc + i : acc }

is a bit harder to read than

puts [1, 2, 3, 4, 5].reduce(0) { |acc, i| acc = acc + 1 if i.to_s =~ /3/ }

but ok I guess that's the price to pay for a compiled language ... and shows that the transition from Ruby to Crystal is not always that easy.

From IRC (bridge bot)
@FromIRC
<riza> mfiano: if the project is following SemVer, then you know that anything which is a breaking change is a major version increment
<mfiano> Ok I see
George Dietrich
@Blacksmoke16
@alex-kampa whats the end goal of this code?
i noticed i had acc + i instead of acc + 1, so are all you wanting to do is count the number of time 3 is in the array?
Alex Kampa
@alex-kampa
counting elements in an array that match a certain regex
at this stage just playing around with various ways to achieve that
George Dietrich
@Blacksmoke16
puts [1, 2, 3, 4, 5].count { |i| i.to_s.matches? /3/ }
or in this specific case puts [1, 2, 3, 4, 5].count 3
Alex Kampa
@alex-kampa
thanks, the ".matches?" looks good, short and idiomatic. I know, RTFD :-)
Thanks @Blacksmoke16
From IRC (bridge bot)
@FromIRC
<mfiano> Is there a way I can run ameba automatically when I "run" or "spec"?
George Dietrich
@Blacksmoke16
setup a Makefile
From IRC (bridge bot)
@FromIRC
<mfiano> Fair enough
George Dietrich
@Blacksmoke16
dont think youd want to run it every time you go to run the program tho
From IRC (bridge bot)
@FromIRC
<mfiano> Probably whenever I spec though
George Dietrich
@Blacksmoke16
yea
Jason Waldrip
@jwaldrip
alright, solved that one... next Q
how is is possible to call .from_json on an abstract class and have it resolve to one of its decendants?
From IRC (bridge bot)
@FromIRC
<mfiano> Ah cool, no Makefile required
George Dietrich
@Blacksmoke16
crystal spec && ./bin/ameba?
From IRC (bridge bot)
@FromIRC
<mfiano> on save, vim-crystal seems to annotate the margin and with error icons, and when cursor is on one of those lines, message in status bar