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 7848983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:23:23+00:00 2026-06-02T18:23:23+00:00

Like in title – for example I have a method DrawMe(what) and I want

  • 0

Like in title – for example I have a method DrawMe(what) and I want to allow to run this method when what argument is equal to one of this values: {"house", "garden", "cat", "dog"} – and if not then this method should be stopped and an error should be printed. Any ideas?

  • 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-06-02T18:23:24+00:00Added an answer on June 2, 2026 at 6:23 pm
    class Draw
      ALLOWED = %w[house garden cat dog]
      def self.me(what)
        raise ArgumentError, "Unknown drawable '#{what}'" unless ALLOWED.include?(what)
        # Otherwise, carry on!
        puts "I'm going to draw a #{what}!"
      end
    end
    
    Draw.me('garden') #=> I'm going to draw a garden!
    Draw.me('cat'   ) #=> I'm going to draw a cat!
    Draw.me('morals') #=> RuntimeError: Unknown drawable 'morals'
    

    However, note that most of the time you should not be ensuring that developers passed the right type of value into your method. Your method will raise its own error if something explodes as a result of misuse; it’s a waste of your time and the computer’s time to attempt to check and catch errors like this.

    Edit: If you need to use this frequently, you could monkeypatch it in everywhere:

    class Object
      def ensure_in( enumerable )
        unless enumerable.include?( self )
          raise ArgumentError, "#{self} must be one of #{enumerable}"
        end
      end
    end
    
    def me(what)
      what.ensure_in( ALLOWED )
      # Go ahead
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this in my controller: Konkurrencer.where(title LIKE ?, %#{params[:q]}%).limit(4) I think this query
hello all i have one json object like {event1:{title:My birthday,start:12\/27\/2011 10:20 ,end:12\/27\/2011 00:00 },event2:{title:My
I have a text like: Title A some description on a few lines, there
My config file looks like this: title = myTitle; otherTitle = myOtherTitle; when I
I would like to make every EditText object have own title like in Pure
Say I have a JSON string like: {title:aaa,url:bbb,image:{url:ccc,width:100,height:200}, ... My accessor: import com.google.gson.annotations.SerializedName; public
I have a table lists containing list information like title and id (auto_increment) and
I use a form where i have listed the data from database like title,
I have an array filled with dictionaries. Each dictionary have strings like title, info
In javascript, I've got a block of HTML like this: <h2>{title}</h2> <p><a href={url}>{content}</a></p> And

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.