Google Group for clj-record
The title pretty much says it all. There's now a Google Group for discussion of clj-record: clj-record-dev.
The title pretty much says it all. There's now a Google Group for discussion of clj-record: clj-record-dev.
Posted by
John Hume
at
10:55 AM
2
comments
You could always define instance-specific behavior on Renum values the same way you can on any object in Ruby:
enum :FakeWord do
Foo()
Bar()
Baz()
def extra_stuff
"no extra stuff here"
end
end
def Foo.extra_stuff
"here's the foo stuff"
end
That works fine, but it's a little ugly.
Starting this afternoon (with release 1.1) you can do this instead:
enum :FakeWord do
Foo do
def extra_stuff
"here's the foo stuff"
end
end
Bar()
Baz()
def extra_stuff
"no extra stuff here"
end
end
FakeWord::Foo will have its own implementation of extra_stuff while FakeWord::Bar and FakeWord::Baz will have the one defined inside the enum block. This was implemented by just instance_eval'ing the given block against the instance just after creating it. A def form in an instance_eval'd block ends up defining a singleton method, so it's equivalent to the uglier version above.
This ends up looking almost exactly like the Java enum equivalent for defining constant-specific class bodies.
Since the block is instance_eval'd, if you prefered you could do any initialization there instead of defining an init method. Depending on what you've got going on it may turn out to be more readable. Here's a contrived example from the spec translated to that style.
# init-with-args-style
enum :Size do
Small("Really really tiny")
Medium("Sort of in the middle")
Large("Quite big")
attr_reader :description
def init description
@description = description
end
end
# instance-block-per-value-style
enum :Size do
Small { @description = "Really really tiny" }
Medium { @description = "Sort of in the middle" }
Large { @description = "Quite big" }
attr_reader :description
end
The latter is probably slightly easier to digest, but it's also an extremely simple case, so I'd expect your mileage to vary quite a bit. (Note that you can do both an init with arguments AND an associated block. Renum evals the block before calling init, so any instance-specific behavior is in place before your init runs.)
Anyway, comment, suggest, complain, fork, improve, and enjoy.
Posted by
John Hume
at
6:11 PM
2
comments
If you haven't already, you should check out Brian Marick's Agile reboot: Artisanal Retro-Futurism Crossed With Team Scale Anarcho-Syndicalism.
There's a video of his excellent presentation from Agile Roots if you don't feel like reading. There are also stickers you can ask for if you feel like spreading the word.
It's totally tangential to the point, but my favorite quote from the video is near the end of the questions: "...in my observation agile teams care more about delivering business value, often, than the business they're delivering it to."
Posted by
John Hume
at
1:30 PM
0
comments
tagged: agile