Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 06:58
    HertzDevil labeled #11538
  • 06:58
    HertzDevil labeled #11538
  • 06:58
    HertzDevil labeled #11538
  • 06:58
    HertzDevil opened #11538
  • 03:59
    HertzDevil labeled #8413
  • 03:59
    HertzDevil labeled #8413
  • 03:59
    HertzDevil labeled #8413
  • 03:57
    HertzDevil closed #6510
  • 03:55
    HertzDevil labeled #6373
  • 03:54
    HertzDevil labeled #7305
  • 03:54
    HertzDevil labeled #7305
  • 03:47
    HertzDevil labeled #7455
  • 03:47
    HertzDevil labeled #7457
  • 03:47
    HertzDevil labeled #7457
  • 03:32
    HertzDevil synchronize #11229
  • 03:13
    HertzDevil synchronize #11230
  • 03:09
    HertzDevil synchronize #11230
  • 02:57
    HertzDevil synchronize #11145
  • 02:53
    HertzDevil closed #11233
  • Dec 03 17:47
    HertzDevil edited #11537
manveru
@manveru:matrix.org
[m]
ah, the annotation is on the instance var
thanks :)
From IRC (bridge bot)
@FromIRC
<mfiano> I'm trying to affect how an instance of a struct prints with puts, but defining a custom to_s in the struct scope doesn't seem to do anything. What is the correct way?
George Dietrich
@Blacksmoke16
def to_s(io : IO) : Nil
then write the content to that io
From IRC (bridge bot)
@FromIRC
<mfiano> Perfect, thanks.
George Dietrich
@Blacksmoke16
there's also def inspect(io : IO) : Nil which is similar but diff
From IRC (bridge bot)
@FromIRC
* mfiano reads
<mfiano> I see.
<mfiano> Crystal is just amazing me the more I learn it. I'm pretty excited to be getting started. It's so nice to be able to just write what I mean with minimal syntax/short symbols like "to_s".
George Dietrich
@Blacksmoke16
fun fact, to_s also gets invoked if you add a var into a string. I.e. puts "Hello #{user}" is the same as puts "Hello #{user.to_s}"
From IRC (bridge bot)
@FromIRC
<mfiano> I remember reading the performance gotchas about that
From IRC (bridge bot)
@FromIRC
<mfiano> I'm struggling with multiple struct constructors. I have a struct, Foo, with @a and @b variables. I'd like to invoke it as Foo.new(1.2, 3.4), or Foo.new(1.2), in which case, @a and @b would be set to 1.2.
George Dietrich
@Blacksmoke16
is the 2nd value just the first one doupeld?
doubled
From IRC (bridge bot)
@FromIRC
<mfiano> Given one argument, both variables should be set to the same value.
George Dietrich
@Blacksmoke16
def self.new(value : Float64) : self
  new value, value
end

def initialize(@a : Float64, @b : Float64); end
should do it
From IRC (bridge bot)
@FromIRC
<mfiano> Ah so you can only have 1 initialize method?
<mfiano> I was trying to overload that multiple times :⁠/
George Dietrich
@Blacksmoke16
no, but
tl;dr i always just mke initialize represent the actual state of the instance, but then have overloaded .new to transform the arguments into something the initializer constructs
expects*
From IRC (bridge bot)
@FromIRC
<mfiano> That post was very well explained, thanks.
George Dietrich
@Blacksmoke16
From IRC (bridge bot)
@FromIRC
<mfiano> Is there a way to alias a module at the file level?
<mfiano> I don't want to remove the full qualification, but for a long/deep module that is used all over a single file, I would like to alias it to a single character or something
George Dietrich
@Blacksmoke16
technically no, but you shouldn't need to provide the FQN if its in the same namespace

or if its in a diff namespace you can do like

```

private alias Foo = MyApp::Some::Very::Long::Namespace::Foo
private top level aliases are scoped to the file they're defined in
From IRC (bridge bot)
@FromIRC
<mfiano> Oh! I wasn't aware that program-level private stuff was file-local
From IRC (bridge bot)
@FromIRC
<mfiano> That is great
mfiano
@mjfiano:matrix.org
[m]
test
Taupiqueur
@alexherbo2
why I can't refer to Scope in Snippet::Parser?
I have Snippet::Scope struct defined, it can't find it
George Dietrich
@Blacksmoke16
can you share the code/error?
Taupiqueur
@alexherbo2
George Dietrich
@Blacksmoke16
seems the error is coming from YAML::Serializable, can you include more of the strack trace?
Taupiqueur
@alexherbo2
it's odd because if I replace struct Snippet::Scope { with struct Scope, it finds it
George Dietrich
@Blacksmoke16
what happens if you rename the struct to like Snippet::Scope2
Taupiqueur
@alexherbo2
Same error
Can it be due to my forwarded block in Walk filter?
George Dietrich
@Blacksmoke16
im not sure
Taupiqueur
@alexherbo2
I haven't found a way to use return like in other filtering methods