Is it possible to handle 'magic' property assignments a'la PHP?

Jacob Carlborg doob at me.com
Sun Jan 5 08:18:21 PST 2014


On 2014-01-05 14:09, Philippe Sigaud wrote:

> As Adam showed, it's very nice to make some clean API (or DSL).
>
> Another example I like is generating queries:
>
> auto result = table.findByFirstName;
>
> If Table has a "FirstName" field, then opDispatch will catch any
> findByXXXXX and generate the related query. A bit like Activerecord
> for Ruby.

Just for the record. In Rails, that's the old, now discourage, Rails 2 
syntax. In Rails 3 and later the following syntax is preferred:

Table.where(first_name: "foo").first

Which in D would look like:

Table.where(["first_name": "foo"]).first;

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list