Skip to content

Commit

Permalink
Ruby 1.8.6 didn;t seem to like my define methods, added class_eval st…
Browse files Browse the repository at this point in the history
…rings, not as nice though
  • Loading branch information
Matt Haynes committed Jun 16, 2010
1 parent a344e5e commit 2fb0680
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Install the software (for more info see the Installation section) and run with:

ruby mayapp.rb

View your graph at [http://localhost/a\_graph\_of\_various\_fruit.png](http://localhost/a_graph_of_various_fruit.png)
View your graph at [http://localhost:4567/a\_graph\_of\_various\_fruit.png](http://localhost:4567/a_graph_of_various_fruit.png)

## Installation

Expand Down
2 changes: 1 addition & 1 deletion chart-topper.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Gem::Specification.new do |s|
s.name = "chart-topper"
s.version = "0.0.1"
s.version = "0.0.2"
s.author = "Matt Haynes"
s.email = "[email protected]"
s.homepage = "http://github.com/matth/chart-topper/tree/master"
Expand Down
Binary file added examples/a_simple_line_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# BAR CHART /a_simple_bar_chart.png
bar "A simple bar chart" do

size "400x225"
size params["size"] || "400x225"

data "Apples", 40
data "Oranges", 50
Expand Down
19 changes: 13 additions & 6 deletions lib/sinatra/chart_topper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ module ChartTopper
:pie, :side_stacked_bar, :side_bar, :spider, :stacked_area, :stacked_bar]

GRAPH_TYPES.each do |method|
define_method(method) do |*args, &block|

This comment has been minimized.

Copy link
@rkh

rkh Jun 16, 2010

define_method(method) do |*args|

title, options = *args
options ||= {}
camelized = method.to_s.split('_').map {|w| w.capitalize}.join
draw Gruff.const_get(camelized), title, options, &block

This comment has been minimized.

Copy link
@rkh

rkh Jun 16, 2010

draw(Gruff.const_get(camelized), title, options) { |*a| yield(*a) }

end
# Ruby 1.8.6 doesn't seem to like this ???
# define_method(method) do |*args, &block|
# title, options = *args
# options ||= {}
# camelized = method.to_s.split('_').map {|w| w.capitalize}.join
# draw Gruff.const_get(camelized), title, options, &block
# end
camelized = method.to_s.split('_').map {|w| w.capitalize}.join
class_eval <<-EVAL
def #{method.to_s}(title, options ={}, &block)
draw #{Gruff.const_get(camelized)}, title, options, &block
end
EVAL
end

# Delegate(?) these methods to the graph
Expand Down

2 comments on commit 2fb0680

@rkh
Copy link

@rkh rkh commented on 2fb0680 Jun 16, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 1.8.6, blocks cannot take a block argument. But I think it's high time to drop 1.8.6 support anyway.

@matth
Copy link
Owner

@matth matth commented on 2fb0680 Jun 16, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rkh Yep, sounds reasonable and the clas_eval is a pretty ugly solution. Just need to get my work machine's updated :)

Please sign in to comment.