Quantcast
Channel: Notes posted to Ruby
Browsing all 21 articles
Browse latest View live

group on hash (Enumerable#group_by)

‘ def group_by_hash hash, value hash.group_by do |k,v| v > value ? "Big" : "Small" end end marks = {"Chair" => 30, "Table" => 40, "Bed" => 60, "stool" => 20} group_by_hash(marks, 30)

View Article



Why module_function creates a private method, when including the module?...

What’s the intention for doing that?

View Article

more loops (Kernel#loop)

fruits = [‘apple’,‘orange”] fruits.each do |fruit| puts "A fruit of type: #{fruit}" end

View Article

Step-By-Step Guide to Building Your First Ruby Gem (Kernel#loop)

Nowadays all the functionalities in Rails are built as Ruby gems. For example we can use devise gem for the authentication part of the application. It’s like a package or library that is written in...

View Article

How to Add Functionality to Ruby Classes with Decorators (Kernel#loop)

Decorators allow us to add behavior to objects in runtime and don’t affect other objects of the class. Decorators can be applied when you need to dynamically add and remove responsibility to a class....

View Article


Volt Framework for Ruby (Module#alias_method)

Volt – a new Framework for Ruby where both the server and client sides are written in Ruby via OPAL (a ruby to JavaScript compiler) so developer can write dynamic applications without writing a single...

View Article

Scheduling Recurring Events with Ice Cube Gem (Module#alias_method)

Ice_cube is a ruby library for effectively taking care of repeated events (schedules). The force lies in the ability to indicate multiple rules, and have ice_cube rapidly make sense of whether the...

View Article

How to use Acts_As_Votable Gem (Module#alias_method)

Acts_As_Votable is ruby gem specifically written for Rails/ActiveRecord models and This gem allows any model to be voted on upvote/downvote like/dislike, etc. It allows any model to be voted under...

View Article


Examples corrected (Module#alias_method)

I have documented this method clearly with corrections to the examples shown in this page on my blog: http://www.rubyplus.net/2016/11/aliasmethod-in-ruby.html

View Article


Ruby Developers (Module#alias_method)

How to create a Ruby Gem Ruby Gems or “gem” is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries. It is easy to manage...

View Article

Code Refactoring Gem – Flay (Module#alias_method)

Flay examines code for structural likenesses. Differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, props versus do/end, and so forth are all...

View Article

Rails caching with dalli gem (Module#alias_method)

Dalli is a high performance pure Ruby client for accessing memcached servers. It works with memcached 1.4+ only, as it uses the newer binary protocol. Memcache Memcached is a quick in-memory protest...

View Article

Clarifying the confusing example (Module#alias_method)

since exit is a keyword in Ruby, the example may be confusing. The following example might be less so: module Foo begin # this raises an error b/c baz is not defined here alias_method :other_baz, :baz...

View Article


Sort Integers (Array#sort!)

ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16] Sort From Greatest to Smallest >> [1, 2, 3, 4].sort { |a, z| z <=> a } => [4, 3, 2, 1]

View Article

nope (Net::FTP#gettextfile)

If you pass nil as local file, it doesn’t write the file and only returns the content as string.

View Article


And yet another way to get relative path from absolute globbing (Dir#glob)

If you execute glob within a block passed to Dir.chdir, you get the paths relative to the directory specified by Dir.chdir… like this… base_dir = '/path/to/dir' files = Dir.chdir(base_dir) do...

View Article

Faker Gem: Fake Data Generation in Ruby (Dir#glob)

Gems are libraries in Rails that generally enable you to write the application code faster and thereby making a great product in far lesser time. Usually, whenever we start developing any application,...

View Article


Urlify Functions & Its Implementation (Dir#glob)

URLify is a simple gem that refines the conversion of UTF-8 strings to ASCII-safe URI strings and enables it to be used as readable URL-segments. After the gem is installed, you can call the URLify...

View Article

define_method with blocks works differently (Module#define_method)

As it is already stated that block is evaluated using instance_exec/instance_eval, so let me give you an example. module Service module ClassMethods def endpoint_instance_exec(name, &block)...

View Article

OUTDATED!!! (Time#strftime)

Man, this stuff is so outdated. Be very careful using anything from here. A lot has changed since Ruby 1.9. You’ll want to look at the updated docs, like here for Ruby 2.5.1:...

View Article
Browsing all 21 articles
Browse latest View live




Latest Images