Code Test - Ruby

Moderator: Moderators

<<

Dan Rathbun

Very New Member
Very New Member

Posts: 7

Joined: Tue Jun 29, 2010 5:04 pm

Post Tue Jun 29, 2010 5:57 pm

Code Test - Ruby

[ Toggle ]
Note: to Moderators
Please forgive this test post in this forum, as I could not post in the BBCode (Hooker) Test Posts forum (no "New Topic" button.)
Moderators - Feel free to grab the code example(s) and re-post in that forum, then delete this post.


Example 1:
Syntax: [ Download ] [ Hide ]
Using Ruby Syntax Highlighting

class Geom::Vector3d

  #  upright?
  #
  #  Orthogonal method. (ie: Directed upward and being at a right
  #    angle to the horizon.)
  #
  #  Returns (boolean) true if vector.z is both parallel to the
  #    z axis, and is in the +z direction.  
  #  Returns false if the face is not parallel to the z axis,
  #    or if the vector.z direction is negative.
  #
  #  Exceptions: none
  #
  #  See Also: vertical? (boolean) method, to find whether a vector
  #    is parallel to the z axis, without regard to direction.
  #
  def upright?
    #--
    #  :
    #++
    return self.parallel?([0,0,1]) && self.z>0
  end

end # class Geom::Vector3d
 
Parsed in 0.003 seconds, using GeSHi 1.0.8.11


Example 2:
Syntax: [ Download ] [ Hide ]
Using Ruby Syntax Highlighting
#
#  app_safe_shutdown.rb
#  
#  defines Sketchup::app_safe_shutdown method
#
#  version: 0.1.0 Beta    by Dan Rathbun    22 JUN 2010
#
module Sketchup
  # check first if Google has added this method
  unless ( defined? app_safe_shutdown )=='method'
    if RUBY_PLATFORM.downcase.include?('mswin')
      # add Windows method
      def app_safe_shutdown
        send_action( 57665 ) # v7.1
      end # def
      module_function(:app_safe_shutdown)
    elsif RUBY_PLATFORM.downcase.include?('darwin')
      # add Mac OSX method
      def app_safe_shutdown
        # per Greg Ewing
        send_action('terminate:')
      end # def
      module_function(:app_safe_shutdown)
    else
      # Unsupported platform > silently do nothing!
    end # if
  else
    # already defined
    unless $VERBOSE.nil?
      $stderr.write('Notice: #<!: method Sketchup::app_safe_shutdown was already defined. ')
      $stderr.write("Script&#058; '#{File.basename(__FILE__)}' did NOT redefine the method!>\n")
    end
  end # unless
end # module
 
Parsed in 0.004 seconds, using GeSHi 1.0.8.11

I notice a bug. In the 4th line from the end (of Example 2,) the colon following the word 'Script' within the double quoted string, is being replaced with an HTML numeric character reference (NCR). NCRs are not used in Ruby, and should never replace any character.
We might get around this by escaping the colon (which can work in Ruby, but is not normally neccesary.)
ie:
Syntax: [ Download ] [ Hide ]
Using Ruby Syntax Highlighting

  # 1st bug: works in Ruby, renders incorrect in BBcode (syntax) block
  $stderr.write( "Script&#058; '" << File.basename(__FILE__) << "' was loaded.\n"

  # 2nd bug: works in Ruby, renders incorrect in BBcode (syntax) block
  # using the Ruby %q{ } double quoted string delimiter
  $stderr.write( %q{Script&#058; '} << File.basename(__FILE__) << "' was loaded.\n"

  # Char escaping: works in Ruby, renders correctly in BBcode (syntax) block
  $stderr.write( "Script\: '" << File.basename(__FILE__) << "' was loaded.\n"

 
Parsed in 0.002 seconds, using GeSHi 1.0.8.11
<<

UseLess

User avatar

Village Idiot
Village Idiot

Posts: 272

Joined: Thu Jan 08, 2009 9:57 pm

Location: North East UK

Post Tue Jun 29, 2010 8:58 pm

Re: Code Test - Ruby

Greetings,

Welcome to the forum ;)

Removed my previous post about the problem it's now been fixed and I also now know why it won't work on here.
Movie Quote:
It's not the years honey, it's the mileage...
phpBB 3 Mods @ phpBBStyles

Return to BBCode (Hooker) Test Posts

Who is online

Users browsing this forum: No registered users and 2 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for blacklist.org.