Reputation: 143
I have this method below.
The problem is that I want to pass in twitter_type as a parameter which changes depending on the calling code. The code below works but the method "followers" is hard coded. I want that to be the variable twitter_type. I have tried various ways but get it to work.
def get_change_channel(channel_id, twitter_type)
base_value = Count.where(created_at: Date.yesterday.beginning_of_day..Date.yesterday.end_of_day)
.where(channel_id: channel_id).first.followers
get_current_channel_followers(channel_id) - base_value
end
Thanks for any guidance.
Simon
Upvotes: 0
Views: 57
Reputation: 23307
You can use #public_send
:
def get_change_channel(channel_id, twitter_type)
base_value = Count.where(created_at: Date.yesterday.beginning_of_day..Date.yesterday.end_of_day)
.where(channel_id: channel_id).first.public_send(twitter_type)
Upvotes: 1