Is this a valid call/syntax in ruby?












-3















Is this a valid call/syntax in ruby?



ClassA.ClassB.methodOne(param)









share|improve this question




















  • 3





    It is a valid syntax, but only on the condition ClassB is actually a method (and not contstant/class).

    – Marek Lipka
    Nov 22 '18 at 13:23






  • 2





    It depends how you have defined ClassA, ClassB, methodOne and param. Yes, that is valid syntax that could be made to work. But no, that's probably the wrong way to write whatever it is you're actually trying to do.

    – Tom Lord
    Nov 22 '18 at 13:27











  • I would strongly advise providing more context of your code (a Minimal, Complete, and Verifiable example), so we can explain what a "good way" of doing whatever-it-is could look like.

    – Tom Lord
    Nov 22 '18 at 13:28






  • 2





    BTW I guess it's much easier to answer this question pasteing this snippet into irb console. If it triggers SyntaxError, it's not a valid syntax. If it triggers other error or no error at all, it's a valid syntax.

    – Marek Lipka
    Nov 22 '18 at 13:40











  • Here's what I want to do. def shift_request @message = @shift_request.shift.message() end shift_request belongs to shift shift has many shift_requests but I get an error: undefined method for 'shift' though its a class and not a method of the shift_request

    – Mr. Sinko
    Nov 22 '18 at 13:55
















-3















Is this a valid call/syntax in ruby?



ClassA.ClassB.methodOne(param)









share|improve this question




















  • 3





    It is a valid syntax, but only on the condition ClassB is actually a method (and not contstant/class).

    – Marek Lipka
    Nov 22 '18 at 13:23






  • 2





    It depends how you have defined ClassA, ClassB, methodOne and param. Yes, that is valid syntax that could be made to work. But no, that's probably the wrong way to write whatever it is you're actually trying to do.

    – Tom Lord
    Nov 22 '18 at 13:27











  • I would strongly advise providing more context of your code (a Minimal, Complete, and Verifiable example), so we can explain what a "good way" of doing whatever-it-is could look like.

    – Tom Lord
    Nov 22 '18 at 13:28






  • 2





    BTW I guess it's much easier to answer this question pasteing this snippet into irb console. If it triggers SyntaxError, it's not a valid syntax. If it triggers other error or no error at all, it's a valid syntax.

    – Marek Lipka
    Nov 22 '18 at 13:40











  • Here's what I want to do. def shift_request @message = @shift_request.shift.message() end shift_request belongs to shift shift has many shift_requests but I get an error: undefined method for 'shift' though its a class and not a method of the shift_request

    – Mr. Sinko
    Nov 22 '18 at 13:55














-3












-3








-3








Is this a valid call/syntax in ruby?



ClassA.ClassB.methodOne(param)









share|improve this question
















Is this a valid call/syntax in ruby?



ClassA.ClassB.methodOne(param)






ruby






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 5:13









sawa

131k29202301




131k29202301










asked Nov 22 '18 at 13:19









Mr. SinkoMr. Sinko

64




64








  • 3





    It is a valid syntax, but only on the condition ClassB is actually a method (and not contstant/class).

    – Marek Lipka
    Nov 22 '18 at 13:23






  • 2





    It depends how you have defined ClassA, ClassB, methodOne and param. Yes, that is valid syntax that could be made to work. But no, that's probably the wrong way to write whatever it is you're actually trying to do.

    – Tom Lord
    Nov 22 '18 at 13:27











  • I would strongly advise providing more context of your code (a Minimal, Complete, and Verifiable example), so we can explain what a "good way" of doing whatever-it-is could look like.

    – Tom Lord
    Nov 22 '18 at 13:28






  • 2





    BTW I guess it's much easier to answer this question pasteing this snippet into irb console. If it triggers SyntaxError, it's not a valid syntax. If it triggers other error or no error at all, it's a valid syntax.

    – Marek Lipka
    Nov 22 '18 at 13:40











  • Here's what I want to do. def shift_request @message = @shift_request.shift.message() end shift_request belongs to shift shift has many shift_requests but I get an error: undefined method for 'shift' though its a class and not a method of the shift_request

    – Mr. Sinko
    Nov 22 '18 at 13:55














  • 3





    It is a valid syntax, but only on the condition ClassB is actually a method (and not contstant/class).

    – Marek Lipka
    Nov 22 '18 at 13:23






  • 2





    It depends how you have defined ClassA, ClassB, methodOne and param. Yes, that is valid syntax that could be made to work. But no, that's probably the wrong way to write whatever it is you're actually trying to do.

    – Tom Lord
    Nov 22 '18 at 13:27











  • I would strongly advise providing more context of your code (a Minimal, Complete, and Verifiable example), so we can explain what a "good way" of doing whatever-it-is could look like.

    – Tom Lord
    Nov 22 '18 at 13:28






  • 2





    BTW I guess it's much easier to answer this question pasteing this snippet into irb console. If it triggers SyntaxError, it's not a valid syntax. If it triggers other error or no error at all, it's a valid syntax.

    – Marek Lipka
    Nov 22 '18 at 13:40











  • Here's what I want to do. def shift_request @message = @shift_request.shift.message() end shift_request belongs to shift shift has many shift_requests but I get an error: undefined method for 'shift' though its a class and not a method of the shift_request

    – Mr. Sinko
    Nov 22 '18 at 13:55








3




3





It is a valid syntax, but only on the condition ClassB is actually a method (and not contstant/class).

– Marek Lipka
Nov 22 '18 at 13:23





It is a valid syntax, but only on the condition ClassB is actually a method (and not contstant/class).

– Marek Lipka
Nov 22 '18 at 13:23




2




2





It depends how you have defined ClassA, ClassB, methodOne and param. Yes, that is valid syntax that could be made to work. But no, that's probably the wrong way to write whatever it is you're actually trying to do.

– Tom Lord
Nov 22 '18 at 13:27





It depends how you have defined ClassA, ClassB, methodOne and param. Yes, that is valid syntax that could be made to work. But no, that's probably the wrong way to write whatever it is you're actually trying to do.

– Tom Lord
Nov 22 '18 at 13:27













I would strongly advise providing more context of your code (a Minimal, Complete, and Verifiable example), so we can explain what a "good way" of doing whatever-it-is could look like.

– Tom Lord
Nov 22 '18 at 13:28





I would strongly advise providing more context of your code (a Minimal, Complete, and Verifiable example), so we can explain what a "good way" of doing whatever-it-is could look like.

– Tom Lord
Nov 22 '18 at 13:28




2




2





BTW I guess it's much easier to answer this question pasteing this snippet into irb console. If it triggers SyntaxError, it's not a valid syntax. If it triggers other error or no error at all, it's a valid syntax.

– Marek Lipka
Nov 22 '18 at 13:40





BTW I guess it's much easier to answer this question pasteing this snippet into irb console. If it triggers SyntaxError, it's not a valid syntax. If it triggers other error or no error at all, it's a valid syntax.

– Marek Lipka
Nov 22 '18 at 13:40













Here's what I want to do. def shift_request @message = @shift_request.shift.message() end shift_request belongs to shift shift has many shift_requests but I get an error: undefined method for 'shift' though its a class and not a method of the shift_request

– Mr. Sinko
Nov 22 '18 at 13:55





Here's what I want to do. def shift_request @message = @shift_request.shift.message() end shift_request belongs to shift shift has many shift_requests but I get an error: undefined method for 'shift' though its a class and not a method of the shift_request

– Mr. Sinko
Nov 22 '18 at 13:55












2 Answers
2






active

oldest

votes


















0














You can write like this, NameSpace::ClassName.method_name(param)



Methods should be snakecased.



If you have a model called course/examination (folder/file) and in there method called grade_examination. You would do it like this:



# models/course/examination.rb
class Course::Examination < ApplicationRecord

def self.grade_examination(answers)
#grading code
end
end


When you then call this method you write:



Course::Examination.grade_examination(answers)





share|improve this answer































    0














    As Marek Lipka and Tom Lord said, it depends if ClassA, ClassB, methodOne, and param are methods or a class. However, in ruby everything is an object. For example:




    • 5 <= This is an object (Normally it would be an Integer and could not call a method)

    • time <= This is a method

    • puts <= Print command in ruby


    All 3 combined could look like this:



    5.time { puts "Hello you there."}


    It will print 5 times Hello.



    If you want to read more about ruby check out the documentation.
    http://ruby-doc.org/



    Hope this helps a bit.






    share|improve this answer



















    • 1





      "it depends if ClassA, ClassB, methodOne, and param are methods or a class" – No, it doesn't. Those are all semantic distinctions, they have no bearing on whether something is valid syntax or not.

      – Jörg W Mittag
      Nov 22 '18 at 18:44











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431914%2fis-this-a-valid-call-syntax-in-ruby%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can write like this, NameSpace::ClassName.method_name(param)



    Methods should be snakecased.



    If you have a model called course/examination (folder/file) and in there method called grade_examination. You would do it like this:



    # models/course/examination.rb
    class Course::Examination < ApplicationRecord

    def self.grade_examination(answers)
    #grading code
    end
    end


    When you then call this method you write:



    Course::Examination.grade_examination(answers)





    share|improve this answer




























      0














      You can write like this, NameSpace::ClassName.method_name(param)



      Methods should be snakecased.



      If you have a model called course/examination (folder/file) and in there method called grade_examination. You would do it like this:



      # models/course/examination.rb
      class Course::Examination < ApplicationRecord

      def self.grade_examination(answers)
      #grading code
      end
      end


      When you then call this method you write:



      Course::Examination.grade_examination(answers)





      share|improve this answer


























        0












        0








        0







        You can write like this, NameSpace::ClassName.method_name(param)



        Methods should be snakecased.



        If you have a model called course/examination (folder/file) and in there method called grade_examination. You would do it like this:



        # models/course/examination.rb
        class Course::Examination < ApplicationRecord

        def self.grade_examination(answers)
        #grading code
        end
        end


        When you then call this method you write:



        Course::Examination.grade_examination(answers)





        share|improve this answer













        You can write like this, NameSpace::ClassName.method_name(param)



        Methods should be snakecased.



        If you have a model called course/examination (folder/file) and in there method called grade_examination. You would do it like this:



        # models/course/examination.rb
        class Course::Examination < ApplicationRecord

        def self.grade_examination(answers)
        #grading code
        end
        end


        When you then call this method you write:



        Course::Examination.grade_examination(answers)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 13:31









        kallelundgren93kallelundgren93

        1189




        1189

























            0














            As Marek Lipka and Tom Lord said, it depends if ClassA, ClassB, methodOne, and param are methods or a class. However, in ruby everything is an object. For example:




            • 5 <= This is an object (Normally it would be an Integer and could not call a method)

            • time <= This is a method

            • puts <= Print command in ruby


            All 3 combined could look like this:



            5.time { puts "Hello you there."}


            It will print 5 times Hello.



            If you want to read more about ruby check out the documentation.
            http://ruby-doc.org/



            Hope this helps a bit.






            share|improve this answer



















            • 1





              "it depends if ClassA, ClassB, methodOne, and param are methods or a class" – No, it doesn't. Those are all semantic distinctions, they have no bearing on whether something is valid syntax or not.

              – Jörg W Mittag
              Nov 22 '18 at 18:44
















            0














            As Marek Lipka and Tom Lord said, it depends if ClassA, ClassB, methodOne, and param are methods or a class. However, in ruby everything is an object. For example:




            • 5 <= This is an object (Normally it would be an Integer and could not call a method)

            • time <= This is a method

            • puts <= Print command in ruby


            All 3 combined could look like this:



            5.time { puts "Hello you there."}


            It will print 5 times Hello.



            If you want to read more about ruby check out the documentation.
            http://ruby-doc.org/



            Hope this helps a bit.






            share|improve this answer



















            • 1





              "it depends if ClassA, ClassB, methodOne, and param are methods or a class" – No, it doesn't. Those are all semantic distinctions, they have no bearing on whether something is valid syntax or not.

              – Jörg W Mittag
              Nov 22 '18 at 18:44














            0












            0








            0







            As Marek Lipka and Tom Lord said, it depends if ClassA, ClassB, methodOne, and param are methods or a class. However, in ruby everything is an object. For example:




            • 5 <= This is an object (Normally it would be an Integer and could not call a method)

            • time <= This is a method

            • puts <= Print command in ruby


            All 3 combined could look like this:



            5.time { puts "Hello you there."}


            It will print 5 times Hello.



            If you want to read more about ruby check out the documentation.
            http://ruby-doc.org/



            Hope this helps a bit.






            share|improve this answer













            As Marek Lipka and Tom Lord said, it depends if ClassA, ClassB, methodOne, and param are methods or a class. However, in ruby everything is an object. For example:




            • 5 <= This is an object (Normally it would be an Integer and could not call a method)

            • time <= This is a method

            • puts <= Print command in ruby


            All 3 combined could look like this:



            5.time { puts "Hello you there."}


            It will print 5 times Hello.



            If you want to read more about ruby check out the documentation.
            http://ruby-doc.org/



            Hope this helps a bit.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 '18 at 13:40









            KektutoKektuto

            715




            715








            • 1





              "it depends if ClassA, ClassB, methodOne, and param are methods or a class" – No, it doesn't. Those are all semantic distinctions, they have no bearing on whether something is valid syntax or not.

              – Jörg W Mittag
              Nov 22 '18 at 18:44














            • 1





              "it depends if ClassA, ClassB, methodOne, and param are methods or a class" – No, it doesn't. Those are all semantic distinctions, they have no bearing on whether something is valid syntax or not.

              – Jörg W Mittag
              Nov 22 '18 at 18:44








            1




            1





            "it depends if ClassA, ClassB, methodOne, and param are methods or a class" – No, it doesn't. Those are all semantic distinctions, they have no bearing on whether something is valid syntax or not.

            – Jörg W Mittag
            Nov 22 '18 at 18:44





            "it depends if ClassA, ClassB, methodOne, and param are methods or a class" – No, it doesn't. Those are all semantic distinctions, they have no bearing on whether something is valid syntax or not.

            – Jörg W Mittag
            Nov 22 '18 at 18:44


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431914%2fis-this-a-valid-call-syntax-in-ruby%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin