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 ArticleWhy module_function creates a private method, when including the module?...
What’s the intention for doing that?
View Articlemore loops (Kernel#loop)
fruits = [‘apple’,‘orange”] fruits.each do |fruit| puts "A fruit of type: #{fruit}" end
View ArticleStep-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 ArticleHow 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 ArticleVolt 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 ArticleScheduling 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 ArticleHow 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 ArticleExamples 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 ArticleRuby 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 ArticleCode 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 ArticleRails 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 ArticleClarifying 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 ArticleSort 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 Articlenope (Net::FTP#gettextfile)
If you pass nil as local file, it doesn’t write the file and only returns the content as string.
View ArticleAnd 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 ArticleFaker 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 ArticleUrlify 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 Articledefine_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 ArticleOUTDATED!!! (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
More Pages to Explore .....