amirrajan / rubymotion-applied

RubyMotion documentation provided by the community. Submit a pull request to the docs for a free one year indie subscription.
Apache License 2.0
49 stars 10 forks source link

Module inclusion at compile time on Android doesn't work #122

Open davetrollope-fsml opened 5 years ago

davetrollope-fsml commented 5 years ago

Create a new app. Add the following code to main_activity.rb or another file.

module B
  def d
    true
  end
end

class A
  class << self
    include B

    def c
      true
    end
  end
end

Trying to reference any symbol in the module fails:

(main)> A.c
=> true
(#<MainActivity:0x6366>)> A.d
=> <NoMethodError: undefined method `d' for A:java.lang.Class>

Copy/Pasting the same code in to the repl works

(#<MainActivity:0x6366>)> module B
(#<MainActivity:0x6366>)>     def d
(#<MainActivity:0x6366>)>         true
(#<MainActivity:0x6366>)>     end
(#<MainActivity:0x6366>)> end
=> :d
(#<MainActivity:0x6366>)>
(#<MainActivity:0x6366>)> class A
(#<MainActivity:0x6366>)>     class << self
(#<MainActivity:0x6366>)>         include B
(#<MainActivity:0x6366>)>
(#<MainActivity:0x6366>)>         def c
(#<MainActivity:0x6366>)>             true
(#<MainActivity:0x6366>)>         end
(#<MainActivity:0x6366>)>     end
(#<MainActivity:0x6366>)> end
=> :c
(#<MainActivity:0x6366>)> A.d
=> true
(#<MainActivity:0x6366>)> A.c
=> true