SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Threaded View

  1. #1
    SitePoint Enthusiast jitao's Avatar
    Join Date
    Feb 2003
    Location
    Shanghai
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Can i declare a class twic in Ruby?

    Hi, I'm new to ruby and reading a book "Practical Ruby Projects". And I see some example codes like
    Code Ruby:
    require 'dl/import'
     
    class LiveMIDI
      ON  = 0x90
      OFF = 0x80
      PC  = 0xC0
     
      def initialize
        open
      end
     
      def note_on(channel, note, velocity=64)
        message(ON | channel, note, velocity)
      end
     
      def note_off(channel, note, velocity=64)
        message(OFF | channel, note, velocity)
      end
     
      def program_change(channel, preset)
        message(PC | channel, preset)
      end
    end
     
    if RUBY_PLATFORM.include?('mswin')
     
      class LiveMIDI
        module C
          extend DL::Importable
          dlload 'winmm'
        end
      end
     
    elsif RUBY_PLATFORM.include?('darwin')
      class LiveMIDI
        # Mac code here
      end
    elsif RUBY_PLATFORM.include?('linux')
      class LiveMIDI
        # Linux code here
      end
    else
      raise "Couldn't find a LiveMIDI implementation for your platform"
    end
    I'm quite confused. It looks that the "class LiveMIDI" is declared twice. Is it legal to declare a class at two different places?
    BYW, is there any method in ruby that can print out all the information of an object like "var_dump()" in php?
    Thank you!
    Last edited by jitao; Nov 10, 2009 at 21:20. Reason: format


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •