Search code examples
rubyrubymotion

Where is 'activity' defined in this RubyMotion code?


In this code, 'activity' is used but never defined. Where is it first defined? I'm confused...

https://github.com/HipByte/RubyMotionSamples/blob/master/android/Conference/app/about_fragment.rb#L4


Solution

  • The AboutFragmentclass inherits from Android::App::Fragment, so the most likely answer is that activity is defined as an instance method on Android::App::Fragment.

    A simplified version of how that might work is:

    module Android   
      module App
        class Fragment
          def activity
            "Activity!"
          end
        end
      end
    end
    
    class AboutFragment < Android::App::Fragment
      def onCreateView
        puts activity # Will print "Activity!"
      end
    end