### Home Classes Methods

### In Files

- lib/stella/core_ext.rb

### Parent

Object

### Methods

- ::from_array
- #dump
- #flatten
- #to_http_params
- #to_json

### Files

- LICENSE.txt
- TODO

### Class/Module Index

Quicksearch

- Stella
- Stella::API
- Stella::API::Unauthorized
- Stella::Asserts
- Stella::CLI
- Stella::Client
- Stella::Common
- Stella::Common::PrivacyMethods
- Stella::ET
- Stella::Engine
- Stella::Engine::Base
- Stella::Engine::Base::ClassMethods
- Stella::Engine::Checkup
- Stella::EventTemplate
- Stella::ForcedRedirect
- Stella::HTTPError
- Stella::Log
- Stella::Log::HTTP
- Stella::PageError
- Stella::RT
- Stella::RepeatRequest
- Stella::Report
- Stella::Report::Content
- Stella::Report::Content::ReportMethods
- Stella::Report::Errors
- Stella::Report::Errors::ReportMethods
- Stella::Report::Headers
- Stella::Report::Metrics
- Stella::Report::Metrics::ReportMethods
- Stella::Report::Plugin
- Stella::Report::Plugin::ClassMethods
- Stella::Report::Statuses
- Stella::Report::Statuses::ReportMethods
- Stella::RequestError
- Stella::RequestTemplate
- Stella::Session
- Stella::StringTemplate
- Stella::TP
- Stella::Testplan
- Stella::Testplan::ClassMethods
- Stella::TestplanQuit
- Stella::Testrun
- Stella::TimeoutError
- Stella::UC
- Stella::Usecase
- Stella::Usecase::ClassMethods
- Stella::UsecaseError
- Stella::UsecaseFail
- Stella::Utils
- Stella::VERSION
- Addressable
- Addressable::URI
- Time
- Time::Units
- Array
- DefaultTestplan
- Float
- Hash
- MatchData
- MetricsPack
- Numeric
- Object
- OpenStruct
- StellaBehavior
- StellaError
- String
- Symbol
- Thread

No matching classes.

# Hash

### Public Class Methods

from_array(array = []) click to toggle source

    # File lib/stella/core_ext.rb, line 532
    def self.from_array(array = [])
      h = Hash.new
      array.size.times do |t|
        h[t] = array[t]
      end
      h
    end

### Public Instance Methods

dump(format) click to toggle source

    # File lib/stella/core_ext.rb, line 498
    def dump(format)
      respond_to?(:"to_#{format}") ? send(:"to_#{format}") : raise("Unknown format")
    end

flatten() click to toggle source

Courtesy of Julien Genestoux

    # File lib/stella/core_ext.rb, line 471
    def flatten
      params = {}
      stack = []

      each do |k, v|
        if v.is_a?(Hash)
          stack << [k,v]
        elsif v.is_a?(Array)
          stack << [k,Hash.from_array(v)]
        else
          params[k] =  v
        end
      end

      stack.each do |parent, hash|
        hash.each do |k, v|
          if v.is_a?(Hash)
            stack << ["#{parent}[#{k}]", v]
          else
            params["#{parent}[#{k}]"] = v
          end
        end
      end

      params
    end

to_http_params() click to toggle source

Courtesy of Julien Genestoux See: stackoverflow.com/questions/798710/how-to-turn-a-ruby-hash-into-http-params NOTE: conflicts w/ HTTParty 0.7.3 when named "to_params"

    # File lib/stella/core_ext.rb, line 505
    def to_http_params
      params = ''
      stack = []

      each do |k, v|
        if v.is_a?(Hash)
          stack << [k,v]
        elsif v.is_a?(Array)
          stack << [k,Hash.from_array(v)]
        else
          params << "#{k}=#{v}&"
        end
      end

      stack.each do |parent, hash|
        hash.each do |k, v|
          if v.is_a?(Hash)
            stack << ["#{parent}[#{k}]", URI::Escape.escape(v)]
          else
            params << "#{parent}[#{k}]=#{URI::Escape.escape(v)}&"
          end
        end
      end

      params.chop!
      params
    end

to_json(*args) click to toggle source

    # File lib/stella/core_ext.rb, line 465
    def to_json(*args)
      Yajl::Encoder.encode(self)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.