Skip to content

Refactor constant usage#2

Open
kilgore5 wants to merge 3 commits intojGRUBBS:masterfrom
kingandpartners:refactor-constant-usage
Open

Refactor constant usage#2
kilgore5 wants to merge 3 commits intojGRUBBS:masterfrom
kingandpartners:refactor-constant-usage

Conversation

@kilgore5
Copy link
Contributor

@jGRUBBS see what you think of this.

@kilgore5 kilgore5 mentioned this pull request Mar 19, 2018
1 task

module ClassMethods

# FIX ME: Are these needed?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not seem like these are used / needed

def unique_id(field, block)
const_set('BLOCK', block)
const_set('FIELD', field)
const_set('UNIQUE_IDENTIFIER_FIELD', field)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the more explicit constants. Less likely to be overwritten or override other constants.

def generate_unique_id
return if self.send(self.class::FIELD)
klass = self.class
klass_field = klass.const_get('UNIQUE_IDENTIFIER_FIELD')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const_get is definitely a cleaner approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants