Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6092123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:24:23+00:00 2026-05-23T12:24:23+00:00

My app has 10 features that are enabled/disabled depending upon which of the 3

  • 0

My app has 10 features that are enabled/disabled depending upon which of the 3 ‘types’ of account a user has.

Currently, I have 10 methods (one per feature) along the lines of:

def is_FEATURENAME_enabled
  case currentuser.accounttype
  when "A", "C"  # account types allow to see that feature
    return true
  else
    return false
  end
end

Then, in each place where I potentially disable a feature, I do

if foo.is_SOMEFEATURE_enable
   do stuff to enable that feature
end

It works. It’s not that hard to maintain. But there should be a better way. I suspect the right solution is to define some sort of structure (hash? I dunno) in one place that maps enabled features to accounttypes, then have a single method that I call something like:

if foo.is_feature_enabled(:FEATURENAME)
  do stuff to enable feature
end

where the method is_feature_enabled looks at currentuser.accountype and checks the mapping structure to see if the identified feature is enabled.

And I suspect the DRY way to define that mapping (given I have WAY more features than account types) is to list all the features ONCE then for each feature list the accounttypes that have access to that feature (not the other way around). That way when I add a new feature I only have to edit ONE line in the mapping. Something like:

FeatureA: usertype1
FeatureB: usertype1, usertype3
FeatureC: usertype2
...

seems more logical and easier to maintain than:

usertype1: FeatureA, FeatureB, FeatureD, FeatureG
usertype2: FeatureC, FeatureD
usertype3: FeatureB, FeatureD, FeatureG, FeatureH

Any suggestions would be appreciated, and instructive for learning The Right Way to do stuff in ruby.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:24:24+00:00Added an answer on May 23, 2026 at 12:24 pm

    I think you’ve pretty much discovered the best way to do it on your own– what you suggest is wise. Just use the feature name as a lookup key for your hash, then take the resulting list and check whether that list contains the account type of the current user.

    E.g.,

    # For example...
    $AllowedUserCastes = {
     :CanLogin => ["admin", "paiduser", "crazyuser", "anonymous"],
     :CanDrink => ["admin", "21yearolduser", "crazyuser"],
     :CanArrest => ["admin", "police"]
    }
    
    def featureAllowed?( whichFeature )
        $AllowedUserCastes[whichFeature].include? currentUserCaste()
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, I want to release an app that has all the features of the
The app I'm working on has 4 tabs, 3 of which share many features,
My app has several buttons which trigger different events. The user should NOT be
I have an app that is has been released and is in the app
I have an iPad app that has draggable UIViews contained in a larger parent
I am working on an iPad app, and one of the features that has
My app has an advanced feature that accepts SQL queries written by the user.
I have an application that has iCloud enabled in the Entitlements file, but doesn't
We have an app that uses network, compass, camera and telephony. It has been
I am trying to add accessibility features to an iOS app that has already

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.