Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Feb 05 15:55
    Blacksmoke16 closed #13047
  • Feb 05 15:53
    serge-hulne closed #13047
  • Feb 05 15:45
    Blacksmoke16 edited #13047
  • Feb 05 15:42
    serge-hulne labeled #13047
  • Feb 05 15:42
    serge-hulne opened #13047
  • Feb 05 02:16
    renovate[bot] edited #12735
  • Feb 04 23:27
    straight-shoota milestoned #12966
  • Feb 04 23:27
    straight-shoota milestoned #12966
  • Feb 04 22:45
    Blacksmoke16 synchronize #12966
  • Feb 04 12:51
    straight-shoota closed #12224
  • Feb 04 12:51
    straight-shoota closed #13034
  • Feb 04 12:15
    straight-shoota milestoned #12921
  • Feb 04 12:15
    straight-shoota milestoned #12921
  • Feb 04 10:44
    straight-shoota edited #12921
  • Feb 04 02:39
    cyangle synchronize #12921
  • Feb 04 01:08
    cyangle synchronize #12921
  • Feb 04 01:08
    cyangle synchronize #12921
  • Feb 03 22:11
    straight-shoota labeled #12794
  • Feb 03 22:11
    straight-shoota assigned #12794
  • Feb 03 22:07
    straight-shoota synchronize #12959
From IRC (bridge bot)
@FromIRC
<SamantazFox> Why is it "not okay"?
<SamantazFox> oops, wrong link
<SamantazFox> better
George Dietrich
@Blacksmoke16
because body_io is only set in the context of using the block overload, so body wouldnt be set
while if you used the non block overload body is set and body_io is not
by "not okay" meaning it'll raise saying it shouldn't be nil
if you try to use it in not the right context
From IRC (bridge bot)
@FromIRC
<SamantazFox> Oh, I misunderstood the code snippet you provided
<SamantazFox> Ok, I get it now.
<SamantazFox> Why isn't that mentionned in the API doc?!
George Dietrich
@Blacksmoke16
From IRC (bridge bot)
@FromIRC
<SamantazFox> Ok, thanks y'all
<SamantazFox> Now, I'm wondering why it works sometimes, and not others.
<SamantazFox> And of course impàlement that properly
From IRC (bridge bot)
@FromIRC
<SamantazFox> What's the most recommended? Foo::Bar.echo or Toto::Foo::Bar.echo
George Dietrich
@Blacksmoke16
probably doesnt really matter, could argue the former since its shorter, or the latter because its more clear what specific type it points to
j8r
@jrei:matrix.org
[m]
In rare cases you have no choice of the latter if the stdlib uses the same name
From IRC (bridge bot)
@FromIRC
<SamantazFox> mmmh, okay, thanks :⁠)
Paulo Coghi
@paulocoghi
@naqvis Wow!
Ali Naqvi
@naqvis
:+1:
From IRC (bridge bot)
@FromIRC
<spuun> I have a MetaVar (from @type.instance_vars) which i know is a Hash, but i want to get the key and value types. How? I want to go from the MetaVar to a HashLiteral, I think?
From IRC (bridge bot)
@FromIRC
<spuun> type.type_vars is enough
George Dietrich
@Blacksmoke16
:thumbsup:
Paulo Coghi
@paulocoghi
newbie question: Is it possible to dynamically call an instance method, passing the instance variable name by string?
George Dietrich
@Blacksmoke16
not built in, but it's technically possible to re-create
there is no#send like in Ruby, but id consider redesigning it so you dont need to do that?
Max Fierke
@maxfierke
https://github.com/wyhaines/Send.cr is one such approach to dynamic dispatch in Crystal
Paulo Coghi
@paulocoghi
I am implementing this concept in Crystal (from FeathersJS framework):
hook-flow-3-service.jpg
A library where you can "register" services (that is, class instances) with defined "expected" methods
The main library allow the "registration" of one or more instances
The classes are created by the developer, which must have one or more methods (from the expected ones)
And the library is responsible to (automatically) expose each service on the desired protocol, like a REST API, or Socket, etc
Max Fierke
@maxfierke
one option would be to use the macro finished hook on the base class to collect all the registered sub-classes and do what you need to there
an example of this is in a program where I use the sub-classes of a base class to generate a table/hash of CLI options: https://github.com/maxfierke/mstrap/blob/d5a53cfdd809e35594ec55e58c599edffcd7c2dc/src/mstrap/step.cr#L68-L78
Paulo Coghi
@paulocoghi
Thank you @Blacksmoke16 and @maxfierke

but id consider redesigning it so you dont need to do that?

Agree

From my little knowledge, it seems that using macros is a possible solution, as Max explained with examples
George Dietrich
@Blacksmoke16
define listeners on specific events, the the core logic emits those events
Paulo Coghi
@paulocoghi
Interesting! I will see if I can "automate" this process (or part of it) in order to reduce the syntax for the final developer

In simple terms, I am building a framework with an architecture based on the continuous passing style.

The experience I would like to provide is something like this (the example below is just a draft/idea, not a valid Crystal program) :

Paulo Coghi
@paulocoghi
require "Framework"

# services
require "Users"
require "Messages"

backend = Framework.new()

# create the API endpoint /users
backend.use( "users", Users.new() )

# create the API endpoint /messages
backend.use( "messages", Messages.new() )

# expose the API and listen on the default port
backend.start()
After defining the "services", the develop can "hook" functions before and after a method from a service, creating a "chain" of functions (continuous passing style here), in order to express the business rules (or contract) for each method
George Dietrich
@Blacksmoke16
hmm, how would it handles route arguments and such? I'm not familiar with this pattern, but curious to hear the benefits over other existing frameworks
Paulo Coghi
@paulocoghi
Each hook (which is a function/method) is completely unaware of where it is, or what is the bigger context (from clean architecture)