background preloader

Ruby

Facebook Twitter

Le format de fichier YAML pour les débutants. C’est quoi un fichier YAML YAML est un format de fichier texte pour la sérialisation des données, très utilisé dans la communauté Ruby.

Le format de fichier YAML pour les débutants

YAML vous servira aussi bien pour enregistrer l’état d’une application que pour les fichiers de configuration. Il existe des bibliothèques YAML pour un tas de langages majeurs : C, C++, Ruby, Python, Java, Perl, C#, Javascript, Php, etc… Comment écrire un fichier YAML C’est vraiment très simple. Et voici à quoi ressemble le fichier ‘test.yaml’ : Comment lire un fichier YAML La lecture d’un fichier YAML est presque trop simple : Et voilà ! Random (Ruby 2.2.0) Random provides an interface to Ruby's pseudo-random number generator, or PRNG.

Random (Ruby 2.2.0)

The PRNG produces a deterministic sequence of bits which approximate true randomness. The sequence may be represented by integers, floats, or binary strings. The generator may be initialized with either a system-generated or user-supplied seed value by using ::srand. Ruby Exceptions. The execution and the exception always go together.

Ruby Exceptions

If you are opening a file, which does not exist, then if you did not handle this situation properly, then your program is considered to be of bad quality. The program stops if an exception occurs. So exceptions are used to handle various type of errors, which may occur during a program execution and take appropriate action instead of halting program completely. Rubyconf07 rubyjs. RubyJS. RubyJS : écrire du Ruby en JavaScript ! Il est désormais possible d'utiliser toute la puissance du Ruby en JavaScriptGrâce à cette API complète Vous en rêviez, ils l'ont fait ! Grâce à RubyJS, vous allez pouvoir faire du JavaScript comme du Ruby ! Ruby Talk FAQ · rdp/ruby_tutorials_core Wiki. Welcome to the list of Frequently Asked Questions on the ruby-talk mailing list !

Ruby Talk FAQ · rdp/ruby_tutorials_core Wiki

Feel free to add to it! What are the ruby-talk best practices/guidelines? How do I convert a ruby script into a distributable executable? What is the best Ruby GUI framework? RubyGems Basics - RubyGems Guides. Use of common RubyGems commands The gem command allows you to interact with RubyGems.

RubyGems Basics - RubyGems Guides

Ruby 1.9 and newer ships with RubyGems built-in but you may need to upgrade for bug fixes or new features. To upgrade RubyGems or install it for the first time (if you need to use Ruby 1.9) visit the download page. If you want to see how to require files from a gem, skip ahead to What is a gem.

OCRA

Making a Ruby Script Executable. It’s common knowledge in the *nix community, but for many new developers turning a Ruby script into an executable command line program is akin to magic.

Making a Ruby Script Executable

While there are other references on the internet, for the post here, I will briefly explain how to go from running a Ruby script by invoking Ruby directly, to running the script by its name alone. Game libraries. 2016 Ruby on Rails Rockstar Bundle. Traveling-ruby/TUTORIAL-1.md at master · phusion/traveling-ruby. Traveling Ruby: self-contained, portable Ruby binaries. RubyInstaller for Windows. How to execute a Ruby script in Terminal? Offres d'emploi développeur Ruby et Ruby on Rails. CDI Haute-Savoie (télétravail possible) CodeurAidez les développeurs freelances à trouver des projetsgithubruby-on-rails CDI Paris, france (télétravail possible) Le CollectionistLe "airbnb" des happy fewreactjspostgresqljavascriptfull-stackruby-on-rails.

Offres d'emploi développeur Ruby et Ruby on Rails

Pomodoro_tracker/activity_table_slot.rb at master · PragTob/pomodoro_tracker. How to append text to a file with Ruby. By Alvin Alexander.

How to append text to a file with Ruby

Last updated: Feb 21, 2013 Ruby file FAQ: How do I append text to a file in Ruby? Solution: Appending text to a file with Ruby is similar to other languages: you need to open the file in "append" mode, write your data, and then close the file. Here's a quick example that demonstrates how to append "Hello, world" to a file named myfile.out in the current directory: open('myfile.out', 'a') { |f| f.puts "Hello, world. " } It's very important to note that I use f.puts in that example. Variations. Class Array - Documentation for Ruby 2.0.0. Ary & other_ary → new_ary click to toggle source Set Intersection — Returns a new array containing elements common to the two arrays, excluding any duplicates.

class Array - Documentation for Ruby 2.0.0

The order is preserved from the original array. It compares elements using their hash and eql? Methods for efficiency. Ruby Singleton Pattern. Singleton is perhaps the most hated of all programming patterns.

Ruby Singleton Pattern

You can read some of the reasons for this in Why Singletons are Evil. But, I think it has some good usages. I will start by describing what a singleton pattern is, walk through different ways of implementing it in Ruby, and point to how it's used in Rails. Singleton is a design pattern that restricts instantiation of a class to only one instance that is globally available. It is useful when you need that instance to be accessible in different parts of the application, usually for logging functionality, communication with external systems, database access, etc. Classes et méthodes. Nous sommes maintenant prêts pour créer notre propre classe Adresse. Offres d'emploi développeur Ruby et Ruby on Rails. HTTPResponse (Ruby 2.3.0) Body() click to toggle source Returns the full entity body. Calling this method a second or subsequent time will return the string already read. http.request_get('/index.html') {|res| puts res.body } http.request_get('/index.html') {|res| p res.body.object_id p res.body.object_id } body=(value) click to toggle source Because it may be necessary to modify the body, Eg, decompression this method facilitates that.

Self adjusting windows in shoes. On 2013-05-21 00:54 Is there a way with *shoes* to have a windows that will "grow" according to the information drop on it so the user does not have to scroll? The stmt: Shoes.app :width => 900, :height => 720 creates a fix size windows. I would like to have the windows expand as information is dropped on it. Thank you.

FXRuby

DateTime (Ruby 2.1.1) _strptime(string[, format='%FT%T%z']) → hash click to toggle source Parses the given representation of date and time with the given template, and returns a hash of parsed elements. _strptime does not support specification of flags and width unlike strftime. See also strptime(3) and strftime. static VALUE datetime_s__strptime(int argc, VALUE *argv, VALUE klass) { return date_s__strptime_internal(argc, argv, klass, "%FT%T%z"); } civil([year=-4712[, month=1[, mday=1[, hour=0[, minute=0[, second=0[, offset=0[, start=Date::ITALY]]]]]]]]) → datetime click to toggle source. Packaging to Executables. Learn Ruby on Rails. Learn Ruby on Rails. Struggling With Ruby: Ruby GUI. I have been looking at how easy it would be to put a GUI front-end on Ruby.

Ruby has no native support for a GUI (one place Java and C# really win over Ruby), and while Rails has become the standard for web aplications, there are numerous options for a GUI plug-in. I have had a look at Tk, Fox and Swing (for JRuby). Recently, however, I found Ruby Shoes. Shoes is a very simple GUI, but that is part of its appeal. I doubt it has the comprehensive range of widgets that Tk does, for instance, but it can cope with JPEGs, which Tk cannot (as far as I could find). GitHub - sdsykes/fastimage: FastImage finds the size or type of an image given its uri by fetching as little as needed. String (Ruby 2.2.0) Str % arg → new_str click to toggle source Format—Uses str as a format specification, and returns the result of applying it to arg.

If the format specification contains more than one substitution, then arg must be an Array or Hash containing the values to be substituted. See Kernel::sprintf for details of the format string. static VALUE rb_str_format_m(VALUE str, VALUE arg) { VALUE tmp = rb_check_array_type(arg); if (! NIL_P(tmp)) { VALUE rv = rb_str_format(RARRAY_LENINT(tmp), RARRAY_CONST_PTR(tmp), str); RB_GC_GUARD(tmp); return rv; } return rb_str_format(1, &arg, str); } HTTP (Ruby 2.0.0) An HTTP client API for Ruby.¶ ↑ Net::HTTP provides a rich library which can be used to build HTTP user-agents.

For more details about HTTP see [RFC2616](www.ietf.org/rfc/rfc2616.txt) Net::HTTP is designed to work closely with URI. URI::HTTP#host, URI::HTTP#port and URI::HTTP#request_uri are designed to work with Net::HTTP. If you are only performing a few GET requests you should try OpenURI. Simple Examples¶ ↑ All examples assume you have loaded Net::HTTP with:

JRuby

What is the difference between require_relative and require in Ruby? Releasy. Gosu. Ruby. John Ewart. In Ruby, interfaces are not really a part of the programming paradigm. By its very nature, Ruby is designed to be flexible and loosely-typed, and that provides developers with a lot of power. Over the years I’ve seen a number of projects that are written in Ruby become internally inconsistent. What I mean by this is that developers decide that their abstractions or structure isn’t working and instead of working from the bottom up, just start writing modifications to make things work. Making things work is incredibly valuable, but it can lead to piling up technical debt. Some of these problems feel as though they could be well solved by enforcing interfaces upon developers who are following your programming model. Take, for example, Fog.io, which I mentioned in a previous post. Ruby Exceptions. Raising An Exception An exception is a special kind of object, an instance of the class Exception or a descendant of that class that represents some kind of exceptional condition; it indicates that something has gone wrong.

When this occurs, an exception is raised (or thrown). Companion site to Russ Olsen's book. The Shoes Manual // Traversing the Page. IO. Binread(name, [length [, offset]] ) → string click to toggle source Opens the file, optionally seeks to the given offset, then returns length bytes (defaulting to the rest of the file). binread ensures the file is closed before returning. The open mode would be “rb:ASCII-8BIT”. IO.binread("testfile") IO.binread("testfile", 20) IO.binread("testfile", 20, 10) binwrite(name, string, [offset] ) => fixnum click to toggle source Opens the file, optionally seeks to the given offset, writes string then returns the length written. binwrite ensures the file is closed before returning.

File (Ruby 2.3.0) Array (Ruby 2.2.0) Learn Ruby The Hard Way. If you did the Study Drills from the last exercise you should have seen all sorts of commands (methods/functions) you can give to files. Global variables. XML.com. REXML: Parser des documents XML en Ruby. Parsing an HTML/XML document - Nokogiri 鋸.

Parsing XML with Ruby. Hash. How To Package And Distribute Ruby Applications As a Gem Using RubyGems. Ruby/Tableaux et hachages. Home · Spooner/releasy Wiki. File: README — Documentation for releasy (0.2.2) Packaging to Executables.

Shoes

The Green Shoes Manual // The Styles Master List. The Green Shoes Manual // Hello! The Shoes Manual // Element Creation. Ruby on rails - Insert text into existing file. GUI Applications with Shoes. How to create simple calculator in Ruby Shoes. A Teeny-weeny mp3 player using Ruby and Shoes // RubyLearning Blog. Les Tableaux Ruby : Array en détails. How to create digital clock in Ruby Shoes. The Shoes Manual // Built-in Methods. GitHub - warhammerkid/ruby-audio: ruby-audio wraps around libsndfile to provide simplified sound reading and writing support to ruby programs. Home of audio dev michael chadwick. The Shoes Manual // Built-in Methods. A Teeny-weeny mp3 player using Ruby and Shoes // RubyLearning Blog. GUI Applications with Shoes. AllInOneRuby - A "Just-in-Time and Temporary Installation of Ruby" Packaging to Executables.

Tut-gtk-intro - Ruby-GNOME2 Project Website.

Rails

Your community gem host. Shoes! The easiest little GUI toolkit, for Ruby. Introduction. Tk Tutorial. Ruby/TK Guide. File (Ruby 2.2.0) IO. Graphical User Interfaces: Installing Tk. WxRubyWiki: WxRuby. Ruby Qt tutorial.

FrontPage - Ruby-GNOME2 Project Website. FXRuby. WxRubyWiki: WxRuby. Learn Ruby Programming for Free. Class - Calling another ruby file that is not a gem. De Java à Ruby. Ruby : écrire et LIRE un fichier. Forum du club des développeurs et IT Pro. [Résolu] [Ruby] manipuler des fichiers. Hash.