Ironruby UNLEASHED

Total Page:16

File Type:pdf, Size:1020Kb

Ironruby UNLEASHED Shay Friedman IronRuby UNLEASHED 800 East 96th Street, Indianapolis, Indiana 46240 USA IronRuby Unleashed Editor-in-Chief Copyright © 2010 by Pearson Education, Inc. Karen Gettman All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or Executive Editor otherwise, without written permission from the publisher. No patent liability is assumed Neil Rowe with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no Acquisitions Editor responsibility for errors or omissions. Nor is any liability assumed for damages resulting Brook Farling from the use of the information contained herein. Development Editor ISBN-13: 978-0-672-33078-0 ISBN-10: 0-672-33078-4 Mark Renfrow Library of Congress Cataloging-in-Publication Data Managing Editor Friedman, Shay. Kristy Hart IronRuby unleashed / Shay Friedman. p. cm. Project Editor ISBN 978-0-672-33078-0 Andy Beaster 1. IronRuby (Computer program language) 2. Microsoft .NET Framework. 3. Ruby (Computer program language) I. Title. Copy Editor QA76.73.I586F74 2010 Keith Cline 006.7’882—dc22 2009050114 Indexer Printed in the United States of America Word Wise Publishing First Printing: February 2010 Services Trademarks Proofreader All terms mentioned in this book that are known to be trademarks or service marks San Dee Phillips have been appropriately capitalized. Pearson Education, Inc. cannot attest to the accu- racy of this information. Use of a term in this book should not be regarded as affecting Technical Editor the validity of any trademark or service mark. Justin Etheredge Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possi- Publishing ble, but no warranty or fitness is implied. The information provided is on an “as is” Coordinator basis. The author and the publisher shall have neither liability nor responsibility to any Cindy Teeters person or entity with respect to any loss or damages arising from the information contained in this book. Interior Designer Gary Adair Bulk Sales Pearson offers excellent discounts on this book when ordered in quantity for bulk Cover Designer purchases or special sales. For more information, please contact: Gary Adair U.S. Corporate and Government Sales 1-800-382-3419 Compositor [email protected] Nonie Ratcliff For sales outside of the U.S., please contact: International Sales +1-317-581-3793 [email protected] Contents at a Glance Introduction ..................................................................................... 1 Part I Introduction to IronRuby 1 Introduction to the Ruby Language...................................................... 5 2 Introduction to the .NET Framework .................................................. 13 3 Introduction to the Dynamic Language Runtime (DLR) ....................... 21 4 Getting Started with IronRuby ........................................................... 25 Part II The Ruby Language 5 The Basic Basics................................................................................ 43 6 Ruby’s Code-Containing Structures .................................................... 87 7 The Standard Library....................................................................... 131 8 Advanced Ruby .............................................................................. 161 Part III IronRuby Fundamentals 9 .NET Interoperability Fundamentals ................................................. 207 10 Object-Oriented .NET in IronRuby ................................................... 239 Part IV IronRuby and the .NET World 11 Data Access .................................................................................... 259 12 Windows Forms.............................................................................. 281 13 Windows Presentation Foundation (WPF) ......................................... 303 14 Ruby on Rails ................................................................................. 331 15 ASP.NET MVC ................................................................................ 363 16 Silverlight ...................................................................................... 401 17 Unit Testing ................................................................................... 425 18 Using IronRuby from C#/VB.NET ..................................................... 459 Part V Advanced IronRuby 19 Extending IronRuby ........................................................................ 477 Index.............................................................................................. 511 Table of Contents Introduction 1 Part I Introduction to IronRuby 1 Introduction to the Ruby Language 5 History of the Ruby Language............................................................... 5 Implementations ................................................................................. 6 Features .............................................................................................. 6 Dynamic Language...................................................................... 6 Object Oriented .......................................................................... 7 Duck Typing ............................................................................... 8 Metaprogramming ...................................................................... 9 REPL ........................................................................................ 10 Available Libraries ..................................................................... 11 2 Introduction to the .NET Framework 13 History of the .NET Framework ........................................................... 13 Overview .......................................................................................... 15 Features ............................................................................................ 16 Common Language Infrastructure............................................... 16 Assemblies ................................................................................ 18 Base Class Library ...................................................................... 19 Security .................................................................................... 19 Memory Management................................................................ 19 Frameworks .............................................................................. 20 3 Introduction to the Dynamic Language Runtime 21 Overview .......................................................................................... 22 Features ............................................................................................ 23 Common Hosting Model ........................................................... 23 Runtime Components................................................................ 23 Language Implementation ......................................................... 24 Contents v 4 Getting Started with IronRuby 25 Overview .......................................................................................... 25 Installing IronRuby............................................................................ 26 IronRuby Folders ....................................................................... 29 Getting the Sources ................................................................... 29 Executables and Tools ........................................................................ 30 The IronRuby Interpreter (ir.exe)................................................. 31 File Execution Mode .................................................................. 32 Development Environments ............................................................... 34 Ruby in Steel............................................................................. 34 NetBeans .................................................................................. 35 RubyMine................................................................................. 36 Others ...................................................................................... 37 The Power of IronRuby ...................................................................... 38 Part II The Ruby Language 5 Ruby Basics 43 Basic Syntax ...................................................................................... 43 Comments................................................................................ 43 Setting Values to Variables.......................................................... 44 Calling Methods........................................................................ 45 Code File Structure .................................................................... 46 Coding Standards ...................................................................... 47 Hello World ...................................................................................... 48 Variables ........................................................................................... 48 Numbers................................................................................... 48 Text ......................................................................................... 50 Arrays....................................................................................... 54 Hashes ....................................................................................
Recommended publications
  • Non-Invasive Software Transactional Memory on Top of the Common Language Runtime
    University of Neuchâtel Computer Science Department (IIUN) Master of Science in Computer Science Non-Invasive Software Transactional Memory on top of the Common Language Runtime Florian George Supervised by Prof. Pascal Felber Assisted by Patrick Marlier August 16, 2010 This page is intentionally left blank Table of contents 1 Abstract ................................................................................................................................................. 3 2 Introduction ........................................................................................................................................ 4 3 State of the art .................................................................................................................................... 6 4 The Common Language Infrastructure .................................................................................. 7 4.1 Overview of the Common Language Infrastructure ................................... 8 4.2 Common Language Runtime.................................................................................. 9 4.3 Virtual Execution System ........................................................................................ 9 4.4 Common Type System ........................................................................................... 10 4.5 Common Intermediate Language ..................................................................... 12 4.6 Common Language Specification.....................................................................
    [Show full text]
  • Ironpython in Action
    IronPytho IN ACTION Michael J. Foord Christian Muirhead FOREWORD BY JIM HUGUNIN MANNING IronPython in Action Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> IronPython in Action MICHAEL J. FOORD CHRISTIAN MUIRHEAD MANNING Greenwich (74° w. long.) Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. Sound View Court 3B fax: (609) 877-8256 Greenwich, CT 06830 email: [email protected] ©2009 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15% recycled and processed without the use of elemental chlorine.
    [Show full text]
  • Introducing Visual Studio 2010
    INTRODUCING VISUAL STUDIO 2010 DAVID CHAPPELL MAY 2010 SPONSORED BY MICROSOFT CONTENTS Tools and Modern Software Development ............................................................................................ 3 Understanding Visual Studio 2010 ........................................................................................................ 3 The Components of Visual Studio 2010 ................................................................................................... 4 A Closer Look at Team Foundation Server............................................................................................... 5 Work Item Tracking ............................................................................................................................. 7 Version Control .................................................................................................................................... 8 Build Management: Team Foundation Build ...................................................................................... 9 Reporting and Dashboards.................................................................................................................. 9 Using Visual Studio 2010 ..................................................................................................................... 12 Managing Requirements ....................................................................................................................... 12 Architecting a Solution .........................................................................................................................
    [Show full text]
  • Top 40 .NET Interview Questions & Answers
    https://career.guru99.com/ Guru99 Provides FREE ONLINE TUTORIAL on Various courses like Java | MIS | MongoDB | BigData | Cassandra | Web Services ------------------------------------------------------------------------------------------------------------------------------- SQLite | JSP | Informatica | Accounting | SAP Training | Python ------------------------------------------------------------------------------------------------------------------------------- Excel | ASP Net | HBase | Testing | Selenium | CCNA | NodeJS ------------------------------------------------------------------------------------------------------------------------------- TensorFlow | Data Warehouse | R Programming | Live Projects | DevOps ------------------------------------------------------------------------------------------------------------------------------- Top 40 .NET Interview Questions & Answers 1) Explain what is .NET Framework? The.Net Framework is developed by Microsoft. It provides technologies and tool that is required to build Networked Applications as well as Distributed Web Services and Web Applications. 2) What does .NET Framework provides? .NET Framework renders the necessary compile time and run time foundation to build and run any language that conforms to the Common Language Specification (CLS). 3) Mention what are main components of .Net framework? The main components of .Net framework are Common Language Runtime (CLR) .Net Framework Class Library (FCL) Application Domains Runtime Host Cross-Language Interoperability Side-by-Side Execution
    [Show full text]
  • Open Babel Documentation Release 2.3.1
    Open Babel Documentation Release 2.3.1 Geoffrey R Hutchison Chris Morley Craig James Chris Swain Hans De Winter Tim Vandermeersch Noel M O’Boyle (Ed.) December 05, 2011 Contents 1 Introduction 3 1.1 Goals of the Open Babel project ..................................... 3 1.2 Frequently Asked Questions ....................................... 4 1.3 Thanks .................................................. 7 2 Install Open Babel 9 2.1 Install a binary package ......................................... 9 2.2 Compiling Open Babel .......................................... 9 3 obabel and babel - Convert, Filter and Manipulate Chemical Data 17 3.1 Synopsis ................................................. 17 3.2 Options .................................................. 17 3.3 Examples ................................................. 19 3.4 Differences between babel and obabel .................................. 21 3.5 Format Options .............................................. 22 3.6 Append property values to the title .................................... 22 3.7 Filtering molecules from a multimolecule file .............................. 22 3.8 Substructure and similarity searching .................................. 25 3.9 Sorting molecules ............................................ 25 3.10 Remove duplicate molecules ....................................... 25 3.11 Aliases for chemical groups ....................................... 26 4 The Open Babel GUI 29 4.1 Basic operation .............................................. 29 4.2 Options .................................................
    [Show full text]
  • Configure .NET Code-Access Security
    © 2002 Visual Studio Magazine Fawcette Technical Publications Issue VSM November 2002 Section Black Belt column Main file name VS0211BBt2.rtf Listing file name -- Sidebar file name -- Table file name VS0211BBtb1.rtf Screen capture file names VS0211BBfX.bmp Infographic/illustration file names VS0211BBf1,2.bmp Photos or book scans ISBN 0596003471 Special instructions for Art dept. Editor LT Status TE’d3 Spellchecked (set Language to English U.S.) * PM review Character count 15,093 + 1,162 online table Package length 3.5 (I think, due to no inline code/listings) ToC blurb Learn how to safely grant assemblies permissions to perform operations with external entities such as the file system, registry, UIs, and more. ONLINE SLUGS Name of Magazine VSM November 2002 Name of feature/column/department Black Belt column 180-character blurb Learn how to safely grant assemblies permissions to perform operations with external entities such as the file system, registry, UIs, and more. 90-character blurb Learn how to safely grant assemblies permissions to perform operations with external entities. 90-character blurb describing download NA Locator+ code for article VS0211BB_T Photo (for columnists) location On file TITLE TAG & METATAGS <title> Visual Studio Magazine – Black Belt - Secure Access to Your .NET Code Configure .NET Code-Access Security </title> <!-- Start META Tags --> <meta name="Category" content=" .NET "> <meta name="Subcategory" content=" C#, Visual Basic .NET "> <meta name="Keywords" content=" .NET, C#, Visual Basic .NET, security permission, security evidence, security policy, permission sets, evidence, security, security permission stack walk, custom permission set, code group "> [[ Please check these and add/subtract as you see fit .]] <meta name="DESCRIPTION" content=" Learn how to grant assemblies permissions to perform operations with external entities such as the file system, registry, UIs, and more.
    [Show full text]
  • Alexander, Kleymenov
    Alexander, Kleymenov Key Skills ▪ Ruby ▪ JavaScript ▪ C/C++ ▪ SQL ▪ PL/SQL ▪ XML ▪ UML ▪ Ruby on Rails ▪ EventMachine ▪ Sinatra ▪ JQuery ▪ ExtJS ▪ Databases: Oracle (9i,10g), MySQL, PostgreSQL, MS SQL ▪ noSQL: CouchDB, MongoDB ▪ Messaging: RabbitMQ ▪ Platforms: Linux, Solaris, MacOS X, Windows ▪ Testing: RSpec ▪ TDD, BDD ▪ SOA, OLAP, Data Mining ▪ Agile, Scrum Experience May 2017 – June 2018 Digitalkasten Internet GmbH (Germany, Berlin) Lead Developer B2B & B2C SaaS: Development from the scratch. Ruby, Ruby on Rails, Golang, Elasticsearch, Ruby, Ruby on Rails, Golang, Elasticsearch, Postgresql, Javascript, AngularJS 2 / Angular 5, Ionic 2 & 3, Apache Cordova, RabbitMQ, OpenStack January 2017 – April 2017 (project work) Stellenticket Gmbh (Germany, Berlin) Lead developer Application prototype development with Ruby, Ruby on Rails, Javascript, Backbone.js, Postgresql. September 2016 – December 2016 Part-time work & studying German in Goethe-Institut e.V. (Germany, Berlin) Freelancer & Student Full-stack developer and German A1. May 2016 – September 2016 Tridion Assets Management Gmbh (Germany, Berlin) Team Lead Development team managing. Develop and implement architecture of application HRLab (application for HRs). Software development trainings for team. Planning of software development and life cycle. Ruby, Ruby on Rails, Javascript, Backbone.js, Postgresql, PL/pgSQL, Golang, Redis, Salesforce API November 2015 – May 2016 (Germany, Berlin) Ecratum Gmbh Ruby, Ruby on Rails developer ERP/CRM - Application development with: Ruby 2, RoR4, PostgreSQL, Redis/Elastic, EventMachine, MessageBus, Puma, AWS/EC2, etc. April 2014 — November 2015 (Russia, Moscow - Australia, Melbourne - Munich, Germany - Berlin, Germany) Freelance/DHARMA Dev. Ruby, Ruby on Rails developer notarikon.net Application development with: Ruby 2, RoR 4, PostgreSQL, MongoDB, Javascript (CoffeeScript), AJAX, jQuery, Websockets, Redis + own project: http://featmeat.com – complex service for health control: trainings tracking and data providing to medical adviser.
    [Show full text]
  • Compile-Time Safety and Runtime Performance in Programming Frameworks for Distributed Systems
    Compile-time Safety and Runtime Performance in Programming Frameworks for Distributed Systems lars kroll Doctoral Thesis in Information and Communication Technology School of Electrical Engineering and Computer Science KTH Royal Institute of Technology Stockholm, Sweden 2020 School of Electrical Engineering and Computer Science KTH Royal Institute of Technology TRITA-EECS-AVL-2020:13 SE-164 40 Kista ISBN: 978-91-7873-445-0 SWEDEN Akademisk avhandling som med tillstånd av Kungliga Tekniska Högskolan fram- lägges till offentlig granskning för avläggande av teknologie doktorsexamen i informations- och kommunikationsteknik på fredagen den 6 mars 2020 kl. 13:00 i Sal C, Electrum, Kungliga Tekniska Högskolan, Kistagången 16, Kista. © Lars Kroll, February 2020 Printed by Universitetsservice US-AB IV Abstract Distributed Systems, that is systems that must tolerate partial failures while exploiting parallelism, are a fundamental part of the software landscape today. Yet, their development and design still pose many challenges to developers when it comes to reliability and performance, and these challenges often have a negative impact on developer productivity. Distributed programming frameworks and languages attempt to provide solutions to common challenges, so that application developers can focus on business logic. However, the choice of programming model as provided by a such a framework or language will have significant impact both on the runtime performance of applications, as well as their reliability. In this thesis, we argue for programming models that are statically typed, both for reliability and performance reasons, and that provide powerful abstractions, giving developers the tools to implement fast algorithms without being constrained by the choice of the programming model.
    [Show full text]
  • Design and Implementation of Generics for the .NET Common Language Runtime
    Design and Implementation of Generics for the .NET Common Language Runtime Andrew Kennedy Don Syme Microsoft Research, Cambridge, U.K. fakeÒÒ¸d×ÝÑeg@ÑicÖÓ×ÓfغcÓÑ Abstract cally through an interface definition language, or IDL) that is nec- essary for language interoperation. The Microsoft .NET Common Language Runtime provides a This paper describes the design and implementation of support shared type system, intermediate language and dynamic execution for parametric polymorphism in the CLR. In its initial release, the environment for the implementation and inter-operation of multiple CLR has no support for polymorphism, an omission shared by the source languages. In this paper we extend it with direct support for JVM. Of course, it is always possible to “compile away” polymor- parametric polymorphism (also known as generics), describing the phism by translation, as has been demonstrated in a number of ex- design through examples written in an extended version of the C# tensions to Java [14, 4, 6, 13, 2, 16] that require no change to the programming language, and explaining aspects of implementation JVM, and in compilers for polymorphic languages that target the by reference to a prototype extension to the runtime. JVM or CLR (MLj [3], Haskell, Eiffel, Mercury). However, such Our design is very expressive, supporting parameterized types, systems inevitably suffer drawbacks of some kind, whether through polymorphic static, instance and virtual methods, “F-bounded” source language restrictions (disallowing primitive type instanti- type parameters, instantiation at pointer and value types, polymor- ations to enable a simple erasure-based translation, as in GJ and phic recursion, and exact run-time types.
    [Show full text]
  • Best Recommended Visual Studio Extensions
    Best Recommended Visual Studio Extensions Windowless Agustin enthronizes her cascade so especially that Wilt outstretch very playfully. If necessary or unfooled August usually supple his spruces outhits indissolubly or freest enforcedly and centesimally, how dramaturgic is Rudolph? Delbert crepitated racially. You will reformat your best visual studio extensions quickly open a bit is a development in using frequently used by the references to build crud rest client certifications, stocke quelle mise en collectant et en nuestras páginas Used by Automattic for internal metrics for user activity, nice and large monitors. The focus of this extension is to keep the code dry, and UWP apps. To visual studio extensibility with other operating systems much more readable and let you recommended by agreeing you have gained popularity, make this is through git. How many do, i want it more information and press j to best recommended visual studio extensions installed too would be accessed by the best programming tips and accessible from. If, and always has been an independent body. Unity Snippets is another very capable snippet extension for Unity Developers. Code extension very popular programming language or visual studio extensibility interfaces. The best extensions based on your own dsl model behind this, but using the highlighted in. If you recommended completion. The recommended content network tool for best recommended visual studio extensions out of the method. This can prolong the times it takes to load a project. The best of vs code again after you with vs code is the basics and. Just a custom bracket characters that best recommended visual studio extensions? Extensions i though git projects visual studio is there are mostly coherent ramblings of the latest icon.
    [Show full text]
  • Wavefront Engineering for Manipulating Light-Atom Interactions
    WAVEFRONT ENGINEERING FOR MANIPULATING LIGHT-ATOM INTERACTIONS YEO XI JIE A0140239M [email protected] Report submitted to Department of Physics, National University of Singapore in partial fulfilment for the module PC3288/PC3289 Advanced UROPS in Physics I/II November 2017 Contents 1 Manipulations of Wavefronts 5 1.1 Motivations . 5 1.2 The Spatial Light Modulator (SLM) . 5 1.3 Controlling the SLM . 8 1.3.1 The Meadowlark XY Series SLM (P512L) . 8 1.3.2 Basic Concepts . 10 1.3.3 Display Configurations . 10 1.3.4 Controlling Phase Shifts with an Image . 10 2 Simple Applications of the SLM 15 2.1 Characterising Phase Shifts of the SLM . 15 2.1.1 Background of Experiment . 15 2.1.2 Implementation . 16 2.2 Beam Displacement by Blazed Grating . 20 2.3 Beam Position Measurements . 24 2.3.1 Method A: Using the birefringence of the SLM . 24 2.3.2 Method B: Fashioning the SLM as a Knife Edge . 26 2.4 Creating Laguerre-Gaussian Mode Beams . 29 3 Measuring Wavefronts 33 1 3.1 Hartmann-Shack Wavefront Sensor . 33 3.1.1 How it Works . 34 3.1.2 A Note on the Lenslet Array . 35 3.2 Zernike Modes . 36 4 Effect of Wavefront Corrections on Fiber Coupling 38 5 Conclusion 44 5.1 Future Outlook . 44 2 Acknowledgements First, I would like to thank Christian Kurtsiefer for giving me the opportunity to work in his group for this project. I would also like to thank everyone in the Quantum Optics group for making my journey through the project enriching and enjoyable, and for the technical help all of you have provided in the lab.
    [Show full text]
  • Moscow ML .Net Owner's Manual
    Moscow ML .Net Owner's Manual Version 0.9.0 of November 2003 Niels Jørgen Kokholm, IT University of Copenhagen, Denmark Peter Sestoft, Royal Veterinary and Agricultural University, Copenhagen, Denmark This document describes Moscow ML .Net 0.9.0, a port of Moscow ML 2.00 to the .Net platform. The focus is on how Moscow ML .Net differs from Moscow ML 2.0. Three other documents, the Moscow ML Owner’s Manual [7], the Moscow ML Language Overview [5] and the Moscow ML Library Documentation [6] describe general aspects of the Moscow ML system. Moscow ML implements Standard ML (SML), as defined in the 1997 Definition of Standard ML, including the SML Modules language and some extensions. Moreover, Moscow ML supports most re- quired parts of the SML Basis Library. It supports separate compilation and the generation of stand-alone executables. The reader is assumed to be familiar with the .Net platform [2]. Contents 1 Characteristics of Moscow ML .Net 2 1.1 Compiling and linking 2 1.2 Command-line options 3 1.3 Additional primitives in the built-in units 3 1.4 The libraries 4 2 Installation 5 3 External programming interface 5 3.1 How external assemblies are found and loaded 5 3.2 How to call a .Net static method from Moscow ML .Net. 6 3.2.1 An example 7 3.2.2 Passing arguments and using results 7 3.2.3 Representation of ML Values 8 3.2.4 Notes 8 3.2.5 An experimental auto-marshalling import mechanism: clr_val 8 3.3 How to call an ML function from .Net 10 3.3.1 Example 10 3.3.2 Experimental, easier export of ML values via exportVal 11 The Moscow ML home page is http://www.dina.kvl.dk/~sestoft/mosml.html 1 1 Characteristics of Moscow ML .Net Unlike most other ports of Moscow ML, this port is not based on porting the Caml Light runtime, but is based on the creation of a new backend that generates .Net CIL code.
    [Show full text]