This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'feedzirra' | |
# fetching a single feed | |
feed = Feedzirra::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing") | |
# feed and entries accessors | |
feed.title # => "Paul Dix Explains Nothing" | |
feed.url # => "http://www.pauldix.net" | |
feed.feed_url # => "http://feeds.feedburner.com/PaulDixExplainsNothing" | |
feed.etag # => "GunxqnEP4NeYhrqq9TyVKTuDnh0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Rails 2.3 features | |
User.admins.first.try(:address).try(:reset) | |
#-------------------------------------------- | |
render :partial => 'articles/article', :locals => { :article => @article } | |
#---> | |
render @article | |
#------------------------------------------- | |
default_scope :order => 'created_at DESC' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Measure the amount bloat you're adding by requiring libraries. | |
# | |
# Usage: | |
# | |
# Bloat.measure do | |
# require 'rubygems' | |
# require 'activesupport' | |
# end | |
# | |
# A report will be printed that tells you how many methods were |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can use {TagsAsClasses} and tranform a tag in a CSS class: | |
A little example: | |
<div class="{TagsAsClasses}">....</div> | |
Add the tag test123 to a post and the relative output code will be: | |
<div class="test123">...</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OpenStruct | |
def to_json | |
table.to_json | |
end | |
end | |
o = OpenStruct.new | |
o.foo = "foo" | |
o.bar = 1 | |
o.to_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
def fullname(first, second) | |
"#{this.firstname} #{first} whatever" | |
end | |
def address(options) | |
"#{street} #{options[:hash_key]}" | |
end | |
def smth(params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7a8 | |
> @methods_params_hash = {} | |
29a31,37 | |
> def methods_with_params | |
> Array(options[:methods]).inject({}) do |method_attributes, method_array| | |
> method_attributes.merge!(method_array) if method_array.is_a?(Hash) | |
> method_attributes | |
> end | |
> end | |
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Operation < ActiveRecord::Base | |
def best | |
created_at | |
end | |
def test(b) | |
"*#{b}*" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=trip_points | |
-include | |
:item | |
:profile | |
:operations | |
-methods do | |
:author | |
current_user | |
:full_name | |
:availability_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calculate_params(context, method_name, params) | |
if params.kind_of?(Array) | |
context.send(method_name, *params) | |
elsif params.kind_of?(Hash) | |
context = context.send(method_name) | |
calculate_params(context, params.keys[0], params.values[0]) | |
elsif params.respond_to?(:to_sym) | |
context.send(method_name, params) | |
else raise ArgumentError, "Unknown type of function params" | |
end |