nskins / goby

Command-line role-playing game framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Less verbose class "Couple"

nskins opened this issue · comments

Currently, Couple.new(a, b) is too tedious to write out every time. Something nice might be like this: (a, b). I know that Arrays and Hashes can be represented in "short" form: [ ] and { }, respectively. Maybe we could implement something similar for Couple?

We should replace every instance in the codebase with the new notation.

Hey I'd like to take a crack at this as my first open-source contribution! Unfortunately there's no way to create your own literals like [] and {} in Ruby. () are protected so you wouldn't be able to create a method from that. Since we're basically trying to alias Class.new here, there are very limited options other than overwriting that method, which is rather dangerous.

However, there is some nice syntactic sugar with brackets you can do which would basically allow you to replace all Couple.new(a, b) with Couple[a, b] by creating a class method to instantiate a new object. I think that's as short and concise as its going to get, but there may be something better out there. Let me know if that's short enough and I'll submit a PR with the changes.