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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:18:41+00:00 2026-06-14T21:18:41+00:00

I have two classes: class Ios REST_ENDPOINT = ‘http://rest’ SOAP_ENDPOINT = ‘http://soap’ end class

  • 0

I have two classes:

class Ios 
  REST_ENDPOINT = 'http://rest'
  SOAP_ENDPOINT = 'http://soap'
end

class Android
  REST_ENDPOINT = 'http://rest'
  SOAP_ENDPOINT = 'http://soap'
end

Then I have two classes for REST and SOAP:

class REST
  def some_action
    # I want to use the endpoint based on device type
  end
end


class SOAP
  def some_action
    # I want to use the endpoint based on device type 
  end
end

How can I use the end_point URLs based on device type in REST and SOAP classes?

Regards,
Kayen

  • 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-14T21:18:42+00:00Added an answer on June 14, 2026 at 9:18 pm

    is this something you are trying to achieve?

    class REST
      def some_action
        ios_url = URI.parse("#{Ios::REST_ENDPOINT}/login")
        android_url = URI.parse("#{Android::REST_ENDPOINT}/login")
      end
    end
    
    class SOAP
      def some_action
        ios_url = URI.parse("#{Ios::SOAP_ENDPOINT}/login")
        android_url = URI.parse("#{Android::SOAP_ENDPOINT}/login")
      end
    end
    

    you could also use some refactoring like this:

    Mixin

    module Endpoints
    
      def initialize device = Ios
        @device = device_class(device)
      end
    
      def url device = nil
        URI.parse "#{endpoint(device || @device)}/login"
      end
    
      def ios_url
        URI.parse "#{endpoint Ios}/login"
      end
    
      def android_url
        URI.parse "#{endpoint Android}/login"
      end
    
      private
      def endpoint device
        device_class(device).const_get self.class.name + '_ENDPOINT'
      end
    
      def device_class device
        device.is_a?(Class) ? 
          device : 
          Object.const_get(device.to_s.capitalize)
      end
    
    end
    

    Include Mixin in your classes

    class REST
      include Endpoints
    
      def some_action
        # use ios_url and android_url here
      end
    end
    
    class SOAP
      include Endpoints
    
      def some_action
        # use ios_url and android_url here
      end
    end
    

    Some Testing:

    puts REST.new(:Ios).url
    #=> http://ios-rest.com/login
    
    puts REST.new.url :Ios
    #=> http://ios-rest.com/login
    
    puts REST.new.ios_url
    #=> http://ios-rest.com/login
    
    
    puts REST.new(:Android).url
    #=> http://android-rest.com/login
    
    puts REST.new.url :Android
    #=> http://android-rest.com/login
    
    puts SOAP.new.android_url
    #=> http://android-soap.com/login
    

    Here is a working demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes: class User < ActiveRecord::Base :has_one :foo end class Foo <
I have two classes class ClassOne def do_something [...] end end class ClassTwo def
I have two classes class A { public string something { get; set; }
Suppose we have two classes: class Base { private: int x; public: void f();
Possible Duplicate: Multiple Inheritance in C# I have two classes Class A and Class
I have two classes: public class MultilingualString { public int Id { get; set;
my code is like this: i have two classes first class: public class Box<E>
I have a problem with hibernate and criterias. I have two Classes: public class
I have these two classes public class Person { } public class Company {
Let's say we have these two classes: public class Base { public static int

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.